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


        }
    }
    本文来自: IT知道网(http://www.itwis.com) 详细出处参考:http://www.itwis.com/html/net/winform/20080420/1313.html

  • 相关阅读:
    输出任意实数
    字谜游戏
    选择问题
    Spark Streaming揭秘 Day4-事务一致性(Exactly one)
    Spark Streaming揭秘 Day3-运行基石(JobScheduler)大揭秘
    Spark Streaming揭秘 Day2-五大核心特征
    Spark Streaming揭秘 Day1-三大谜团
    深度学习在美团搜索广告排序的应用实践
    美团外卖客户端高可用建设体系
    大众点评账号业务高可用进阶之路
  • 原文地址:https://www.cnblogs.com/freeliver54/p/1234225.html
Copyright © 2011-2022 走看看