[0] C#实现WebBrowser&HTML交互

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

  
namespace WindowsApplication5
{
  
publicpartialclass Form1 : Form
  {
    
public Form1()
    {
     InitializeComponent();
    }

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。