user276351
user276351

Reputation:

How to call the Click event on a page in the Windows Forms WebBrowser control?

How call Click event on button in WebBrowser control?

Upvotes: 0

Views: 1377

Answers (2)

Hans Passant
Hans Passant

Reputation: 941208

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");
  }
}

Upvotes: 1

John Weldon
John Weldon

Reputation: 40739

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?

Upvotes: 0

Related Questions