【问题标题】:How to get content in webBrowser control如何在 webBrowser 控件中获取内容
【发布时间】:2011-02-24 02:43:28
【问题描述】:

假设我在文本框中键入 uri 并单击加载按钮,网页被加载到我的 webbrowswer 控件中,然后我突出显示 webbroswer 控件中的一段文本。现在,我怎样才能获得突出显示的文本并在另一个文本框中显示? (不可复制/粘贴)

谢谢!

【问题讨论】:

  • 你为什么不想使用复制/粘贴? MSDN 说:“WebBrowser 控件在内部实例化了本机 WebBrowser ActiveX 控件。”因此,如果没有复制/粘贴,访问控件中选定的文本将不是一件容易的事。

标签: wpf


【解决方案1】:

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 属性。
猜你喜欢
  • 1970-01-01
  • 2010-10-11
  • 2012-04-13
  • 2012-04-10
  • 2012-09-27
  • 1970-01-01
  • 2016-11-25
相关资源
最近更新 更多