views:

89

answers:

1

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.

+1  A: 

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!");
    }
}
Hans Passant
Perfect! Thank you.
Tim Murphy