zoukankan      html  css  js  c++  java
  • WebBrowser中html元素如何触发winform事件

    WebBrowser中html元素如何触发winform事件?
    这个问题来自论坛提问,对dom稍微了解的话还是比较简单的,只要注册一下事件就可以了。

    C#代码如下:

    using System;
    using System.ComponentModel;
    using System.Windows.Forms;

    namespace WindowsApplication5
    ...{
        public partial class Form1 : Form
        ...{
            public Form1()
            ...{
                InitializeComponent();
            }
          

            private void Form1_Load(object sender, EventArgs e)
            ...{
                this.webBrowser1.Navigate("www.google.cn");
                this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
            }

            void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            ...{
                if (e.Url.ToString() != this.webBrowser1.Url.ToString()) return;
               foreach(System.Windows.Forms.HtmlElement el in  this.webBrowser1.Document.GetElementsByTagName("input"))
               ...{
                   if (el.Name == "btnG")
                   ...{
                       el.Click += new HtmlElementEventHandler(Form1_Click);
                   }
               }
               
            }

            void Form1_Click(object sender, HtmlElementEventArgs e)
            ...{
                MessageBox.Show("jinjazz pass");
            }


        }
    }

  • 相关阅读:
    HTTP协议
    php目录操作
    PHP有关类的相关知识
    PHP设计模式
    PHP类的继承
    PHP重写
    php类中成员
    php面向对象
    什么是SVN
    ThinkPHP5 初识路由
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/1294281.html
Copyright © 2011-2022 走看看