2
在WinForms应用程序中,我需要检测System.Windows.Forms.WebBrowser的内容何时被双击,从而打开自定义的Winform对话框。如何检测双击WebBrower控件?
我注意到WebBrowserBase禁用了Control.DoubleClick事件,但我还没有弄清楚如何覆盖这种行为。
在WinForms应用程序中,我需要检测System.Windows.Forms.WebBrowser的内容何时被双击,从而打开自定义的Winform对话框。如何检测双击WebBrower控件?
我注意到WebBrowserBase禁用了Control.DoubleClick事件,但我还没有弄清楚如何覆盖这种行为。
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!");
}
}
完美!谢谢。 – 2010-05-13 13:34:35