当我单击表单(winform)中的按钮时,我想显示一个网页(谷歌)......
我已经尝试了下面的代码,但它对我不起作用......
public partial class Form1 : Form {
bool mHooked;
public Form1() {
InitializeComponent();
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
webBrowser1.Navigate("http://www.google.com");
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
if (mHooked) return;
// Get the form
HtmlDocument doc = webBrowser1.Document;
HtmlElement form = doc.Forms["f"];
// Get the "I'm feeling lucky" button
HtmlElement lucky = form.All["btnI"];
lucky.Click += lucky_Click;
mHooked = true;
}
void lucky_Click(object sender, EventArgs e) {
this.Close();
}
}
我正在使用 c# 做 winforms 应用程序
有人可以帮忙吗.....
提前谢谢了...