1.窗体
2.后台代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Da
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EC_Tool.test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//設置當前文檔為百度
this.webBrowser1.Url = new Uri("http://www.baidu.com");
}
private void btnSearch_Click(object sender, EventArgs e)
{
//得到當前文檔
HtmlDocument htmlDoc = this.webBrowser1.Document;
//將我們在WinForm窗體的文本框中輸入的值同步到百度,kw是百度關鍵字輸入框的ID
htmlDoc.All["kw"].SetAttribute("value", this.txtKeyword.Text);
//調用按鈕“百度一下”的點擊事件,su是按鈕ID
htmlDoc.All["su"].InvokeMember("click");
}
}
}
3.运行,在文本框里输入“sb”,点击“搜索”按钮,结果如下图