In a WinForms application I need to detect when the contents of a System.Windows.Forms.WebBrowser is double clicked which in turn opens custom winform dialog box.
I note that WebBrowserBase disables the Control.DoubleClick event but I've not worked out how to override this behaviour.
MouseDown is disabled too. That's because mouse events are sent to the DOM. You can subscribe to DOM events with the HtmlElement.AttachEventHandler() method. For example:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
webBrowser1.Url = new Uri("http://stackoverflow.com");
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
webBrowser1.Document.Body.AttachEventHandler("ondblclick", Document_DoubleClick);
}
void Document_DoubleClick(object sender, EventArgs e) {
MessageBox.Show("double click!");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With