c# webbrowser 获取用户选中文字
??? 最近一直被一個問題困擾,有一個文本框,一個webbrowser控件,一個上下文菜單,
用戶用鼠標左鍵選中文字,右鍵點擊搜索,就把選中的文字賦給文本框的TEXT,便可以遞進搜索,在網(wǎng)上逛了幾天,也沒有找到好的方法,終于在學(xué)長的幫助下,找到了最終的答案!特拿來與大家分享! 前提條件,你需要添加引用 如圖: 在程序中要添加using mshtml;//獲取用戶選中的文字
??????????? IHTMLDocument2 htmlDocument = webBrowser1.Document.DomDocument as IHTMLDocument2;
??????????? IHTMLSelectionObject currentSelection = htmlDocument.selection;
??????????? if (currentSelection != null)
??????????? { IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;
??????????????? if (range != null)
??????????????? {
??????????????????? //MessageBox.Show(range.text);
??????????????????? tbKeyWord.Text = range.text;
??????????????? }
??????????? }
轉(zhuǎn)載于:https://www.cnblogs.com/lonelyxmas/p/3657763.html
總結(jié)
以上是生活随笔為你收集整理的c# webbrowser 获取用户选中文字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++primer plus第六版课后编
- 下一篇: c# char unsigned_dll