How do I detect a double click on a WebBrower control?
In a WinForms application, I need to detect when the contents of the System.Windows.Forms.WebBrowser are double clicked, in turn, a custom winform dialog will open.
I note that WebBrowserBase disables the Control.DoubleClick event, but I haven't worked out how to override this behavior.
+2
a source to share
1 answer
MouseDown is also disabled. This is because mouse events are sent to the DOM. You can subscribe to DOM events using the HtmlElement.AttachEventHandler () method. For instance:
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!");
}
}
+9
a source to share