Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect double click on WebBrower control?

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.

like image 972
Tim Murphy Avatar asked Jan 19 '26 00:01

Tim Murphy


1 Answers

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!");
    }
}
like image 107
Hans Passant Avatar answered Jan 21 '26 21:01

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!