开发者

How to detect double click on WebBrower control?

开发者 https://www.devze.com 2022-12-29 23:22 出处:网络
In a WinForms application I need to d开发者_如何学Cetect when the contents of a System.Windows.Forms.WebBrowser is double clicked which in turn opens custom winform dialog box.

In a WinForms application I need to d开发者_如何学Cetect 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!");
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消