WebBrowser选择的文本不起作用

时间:2015-03-10 21:46:42

标签: c# webbrowser-control

我想从html文档中获取所选文本,但我的代码存在问题:

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            wb.Navigate(@"D:\s\1.html");



                if (wb.Document != null)
                {
                    IHTMLDocument2 htmlDocument = wb.Document.DomDocument as IHTMLDocument2;

                    IHTMLSelectionObject currentSelection = htmlDocument.selection;


                    if (currentSelection != null)
                    {
                        IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;

                        if (range != null)
                        {
                            textBox1.Text = range.text;
                        }
                    }
                }

        }
    }
}

问题在于它是ArgumentException was unhandeled

IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;

如果有人能给我发一份工作代码或者在我的问题上以某种方式帮助我,我会很感激。

0 个答案:

没有答案