开发者

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

开发者 https://www.devze.com 2022-12-20 09:56 出处:网络
How call Click event on but开发者_运维问答ton in WebBrowser control?Use the HtmlElement.InvokeMember() method.Here\'s an example that clicks the Google home page \"I feel lucky\" button:

How call Click event on but开发者_运维问答ton in WebBrowser control?


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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号