1
假設我在文本框中鍵入uri並單擊按鈕加載,將網頁加載到我的web瀏覽器控件中,然後突出顯示webbroswer控件中的一段文本。現在,我怎樣才能獲得高亮度的文字並在另一個文本框中顯示? (不復制/粘貼)如何在webBrowser控件中獲取內容
謝謝!
假設我在文本框中鍵入uri並單擊按鈕加載,將網頁加載到我的web瀏覽器控件中,然後突出顯示webbroswer控件中的一段文本。現在,我怎樣才能獲得高亮度的文字並在另一個文本框中顯示? (不復制/粘貼)如何在webBrowser控件中獲取內容
謝謝!
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);
}
}
這是用於winforms,而不是用於WPF。 WPF的WebBrowser.Document沒有DomDocument屬性。 – 2014-06-18 12:23:21
爲什麼你不希望使用複製/粘貼? MSDN說:「WebBrowser控件內部實例化本地WebBrowser ActiveX控件」,因此訪問控件中的選定文本將不是一件容易的任務,無需複製/粘貼。 – Jens 2011-02-24 08:48:32