假设我在文本框中输入uri并单击按钮加载,将网页加载到我的webbrowswer控件中,然后我在webbroswer控件中突出显示一段文本。现在,我如何获得高亮显示的文本并在另一个文本框中显示? (没有复制/粘贴)
谢谢!
答案 0 :(得分:3)
Retrieving Selected Text from Webbrowser control in .net(C#)
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);
}
}