Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF WebBrowser Mouse Events not working as expected

I have a WebBrowser object in a WPF Page and I'm trying to do something whenever the user interacts with the page. I have intially tried to use the events associated with the WebBrowser object but they don't seem to be firing. Below is a simplified example of what my code is trying to do:

webBrowser.MouseDown += new MouseButtonEventHandler(webBrowser_MouseDown);

with the event handler as:

void webBrowser_MouseDown(object sender, MouseButtonEventArgs e)
{
  System.Windows.MessageBox.Show("Pressed");
}

However when I run the page and click inside the WebBrowser no message box is displayed.

Apologies, originally I had mentioned that it was a System.Controls WebBrowser rather than a Forms browser.

like image 836
Farthingworth Avatar asked Dec 23 '22 06:12

Farthingworth


1 Answers

Mouse events are not supported by the WebBrowser control, according to the documentation. You need to hook up handlers to the DOM events provided by the document being displayed in the control, using the WebBrowser.Document property. This post has an example of how to do this.

like image 170
Anders Fjeldstad Avatar answered Dec 24 '22 18:12

Anders Fjeldstad