码迷,mamicode.com
首页 > Web开发 > 详细

C# WebBrowser 获得选中部分的html源码

时间:2014-07-10 11:26:42      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:winform   style   blog   http   color   os   

Winform程序 2.0的. 需要引用Microsoft.mshtml.

bubuko.com,布布扣
        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://www.baidu.com");
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
        }

        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser1.Document.MouseUp += new HtmlElementEventHandler(Document_MouseUp);
        }

        void Document_MouseUp(object sender, HtmlElementEventArgs e)
        {
            IHTMLDocument2 document = (IHTMLDocument2)webBrowser1.Document.DomDocument;
            IHTMLTxtRange htmlElem = (IHTMLTxtRange)document.selection.createRange();
            string s = htmlElem.htmlText;
            richTextBox1.Text = s;
        }
View Code

需要看document.selection.createRange();类型 需要引用Microsoft.VisualBasic. 用Microsoft.VisualBasic.Information.TypeName(document.selection.createRange());方法查看类型.

差不多就这些了~ 不知道每次记录这些遇到的问题 能帮助别人不..- -|

C# WebBrowser 获得选中部分的html源码,布布扣,bubuko.com

C# WebBrowser 获得选中部分的html源码

标签:winform   style   blog   http   color   os   

原文地址:http://www.cnblogs.com/guyun/p/3812145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!