【发布时间】:2013-02-21 11:34:50
【问题描述】:
我有一个简单的 C# 应用程序,其中包含按钮和 Web 浏览器,每个按钮执行一个请求并在 Web 浏览器上显示请求的结果。我在下一个按钮中使用请求的结果。
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.test.com");
}
private void button2_Click(object sender, EventArgs e)
{
if (webBrowser1.Document.GetElementById("tesxtbox1") != null)
{
HtmlElement txt1 = webBrowser1.Document.GetElementById("tesxtbox1");
txt1.SetAttribute("value", "test");
webBrowser1.Document.Forms[0].InvokeMember("submit");
}
}
我的问题是找到通过单击执行两个按钮的方法或方式,但是第二个按钮在加载 Web 浏览器之前不执行。 在我的第一个解决方案中,我在第一个按钮中添加了:
webBrowser1.DocumentCompleted + = new WebBrowserDocumentCompletedEventHandler (Button2_Click);
但是第二个按钮执行了几次,所以我在按钮2的最后一行添加了:
webBrowser1.DocumentCompleted - = new WebBrowserDocumentCompletedEventHandler (Button2_Click);
它有效,但在控制台中我发现 Button 2 执行了两次
提前致谢!
【问题讨论】:
-
Execute two buttons with single click 的重复 - 对您的第一个问题的回答对您没有帮助吗?
-
no :( ,我添加 DocumentCompleted 但每个按钮执行 rwice 或更多
标签: c# .net button click browser