109,895
社区成员




这是一个小实现,可以实现自动登录Gmail邮箱。
使用VS2005 C#新建一个 Windows应用程序,
在Form1窗体上添加一个webBrowser控件,
编写如下代码,就可以实现:
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.Url = new Uri("http://www.gmail.com");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement txtUserHtml = webBrowser1.Document.All["Email"];
HtmlElement txtPasswordHtml = webBrowser1.Document.All["Passwd"];
HtmlElement btnClickHtml = webBrowser1.Document.All["signIn"];
txtUserHtml.SetAttribute("value", "这里填写用户名");//输入用户名
txtPasswordHtml.SetAttribute("value", "这里填写密码");//输入密码
btnClickHtml.InvokeMember("click");
}
}
}
这是一个Windows Form与WebBrows交互的小示例。其中涉及到了Web页面上的文本输入框的填写和单击命令按钮的响应。这也是网页表单的最常见形式,填写完信息后,单击命令按钮提交信息。
webBrowser1.Document.GetElementById("控件Id").SetAttribute("value") = "aaaaa";