zoukankan      html  css  js  c++  java
  • C# WebBrowser 获得选中部分的html源码

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

            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;
            }

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

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

  • 相关阅读:
    随机id
    vue关于父组件调用子组件的方法
    ES6——块级作用域
    在vue中引用superMap
    MSSQL备份脚本
    Ubuntu 使用命令导出数据库
    CSS before 中文乱码
    CentOS7 安装linux 网络不联通问题
    SVN update failed问题解决
    JQ实现树形菜单点击高亮
  • 原文地址:https://www.cnblogs.com/lujin49/p/2321272.html
Copyright © 2011-2022 走看看