WPF的WebBrowser鼠标事件未正常工作 [英] WPF WebBrowser Mouse Events not working as expected
问题描述
我有一个WPF页一个WebBrowser对象,我想只要用户与页面交互做一些事情。我已经intially试图使用与web浏览器对象关联的事件,但他们似乎并没有被解雇。下面是什么我的code在试图做一个简单的例子:
I have a WebBrowser object in a WPF Page and I'm trying to do something whenever the user interacts with the page. I have intially tried to use the events associated with the WebBrowser object but they don't seem to be firing. Below is a simplified example of what my code is trying to do:
webBrowser.MouseDown += new MouseButtonEventHandler(webBrowser_MouseDown);
与事件处理程序:
with the event handler as:
void webBrowser_MouseDown(object sender, MouseButtonEventArgs e)
{
System.Windows.MessageBox.Show("Pressed");
}
然而,当我运行该页面,并单击显示没有消息框的web浏览器中。
However when I run the page and click inside the WebBrowser no message box is displayed.
道歉,原来我曾提到,这是一个System.Controls web浏览器,而不是形式的浏览器。
Apologies, originally I had mentioned that it was a System.Controls WebBrowser rather than a Forms browser.
推荐答案
鼠标事件没有被 web浏览器
控件支持,<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser_members.aspx\">according到文档。你需要处理程序挂接到被显示在控制的文件所提供的DOM事件,使用 WebBrowser.Document
属性。 <一href=\"http://social.msdn.microsoft.com/Forums/en-US/Vsex$p$pssvcs/thread/6f292ac0-ccbf-4fc1-88a5-e3b9ea8d862a\">This帖子有如何做到这一点的例子。
Mouse events are not supported by the WebBrowser
control, according to the documentation. You need to hook up handlers to the DOM events provided by the document being displayed in the control, using the WebBrowser.Document
property. This post has an example of how to do this.
这篇关于WPF的WebBrowser鼠标事件未正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!