WPF Net3.5 WebBrowser HTMLElement Mouse Click

Ive used WIndowsFormHost to host the Windows.Forms.WebBrowser control and add an event handler that fires when the user clicks on the HTML element inside the control.

((System.Windows.Forms.WebBrowser)sender).Document.Click -= new System.Windows.Forms.HtmlElementEventHandler(htmlElementClick);

It works well.

I want to do the same in my own .Net3.5 WebBrowser control, how?

I can get HTML document using cover art

var doc = (mshtml.HTMLDocument)myWebBrowser.Document;

and using doc to access HTML content.

But how do I handle a mouse click on an element in an HTML document?

+3
source share
1 answer

Old thread, but this should work:

mshtml.HTMLDocument dom = (mshtml.HTMLDocument)myBrowser.Document;

((mshtml.HTMLDocumentEvents_Event)(dom)).onclick += new mshtml.HTMLDocumentEvents_onclickEventHandler(DocumentClickHandler);

private static bool DocumentClickHandler()
{
    // Do your stuff here

    return true;
}
0
source

Source: https://habr.com/ru/post/1718541/


All Articles