.Net2.0里给WebBrower浏览页面的RadioButton、CheckBox赋值 .

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

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

    private void Form1_Load(object sender, EventArgs e)
    {
      webBrowser1.Navigate("http://www.google.com/intl/zh-CN/");

    }

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
      HtmlDocument doc = webBrowser1.Document;
      HtmlElementCollection inputs = doc.Forms["f"].GetElementsByTagName("INPUT");
      for (int i = 0; i < inputs.Count; i++)
      {
        if (inputs[i].Name == "lr")
        {
          if (inputs[i].GetAttribute("value") == "lang_zh-CN|lang_zh-TW")
            inputs[i].SetAttribute("checked", "true");
        }
      }
    }
  }
}

还有对于select三联动,可采取下列方法:

HtmlElement txtcountry1Html = webBrowser1.Document.All["country1"];
HtmlElement txtprovinceHtml = webBrowser1.Document.All["province"];
HtmlElement txtcityHtml = webBrowser1.Document.All["city"]; 

txtcountry1Html.SetAttribute("value",this.address1.Text);
txtcountry1Html.InvokeMember("onchange");
txtprovinceHtml.SetAttribute("value", this.address2.Text);
txtprovinceHtml.InvokeMember("onchange");
txtcityHtml.SetAttribute("value",this.address3.Text);

你可能感兴趣的:(.Net2.0里给WebBrower浏览页面的RadioButton、CheckBox赋值 .)