如何检测双击WebBrower控件?

Tim*_*phy 2 .net webbrowser-control winforms

在WinForms应用程序中,我需要检测何时双击System.Windows.Forms.WebBrowser的内容,然后打开自定义winform对话框.

我注意到WebBrowserBase禁用了Control.DoubleClick事件,但我还没有弄清楚如何覆盖此行为.

Han*_*ant 9

MouseDown也被禁用.那是因为鼠标事件被发送到DOM.您可以使用HtmlElement.AttachEventHandler()方法订阅DOM事件.例如:

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!");
    }
}
Run Code Online (Sandbox Code Playgroud)