How call Click event on button in WebBrowser control?
views:
71answers:
2
A:
The click event gets invoked in response to a user clicking on the control. You (normally) wouldn't 'call' the event directly yourself.
Can you clarify your question?
John Weldon
2010-02-18 18:22:19
+1 true, poorly stated question, he really should have said something like "how would you interact with controls like buttons on a document in the WebBrowser control"
Tommy
2010-02-19 03:57:14
+1
A:
Use the HtmlElement.InvokeMember() method. Here's an example that clicks the Google home page "I feel lucky" button:
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
if (webBrowser1.Url.Host.EndsWith("google.com")) {
HtmlDocument doc = webBrowser1.Document;
HtmlElement ask = doc.All["q"];
HtmlElement lucky = doc.All["btnI"];
ask.InnerText = "stackoverflow";
lucky.InvokeMember("click");
}
}
Hans Passant
2010-02-18 18:27:14