整个窗口的 MouseHover/MouseLeave 事件
我有 Form 子类,其中包含 MouseHover
和 MouseLeave
的处理程序。当指针位于窗口背景上时,事件正常工作,但当指针移动到窗口内的控件上时,会引发 MouseLeave
事件。
无论如何,是否有一个事件覆盖整个窗口。
(.NET 2.0、Visual Studio 2005、Windows XP。)
I have Form subclass with handlers for MouseHover
and MouseLeave
. When the pointer is on the background of the window, the events work fine, but when the pointer moves onto a control inside the window, it causes a MouseLeave
event.
Is there anyway to have an event covering the whole window.
(.NET 2.0, Visual Studio 2005, Windows XP.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
重写 MouseLeave 事件,使其在鼠标进入子控件时不会触发
Ovveride the MouseLeave event to not trigger so long as the mouse enters a child control
当鼠标离开事件被触发时,一种选择是检查指针的当前位置并查看它是否在表单区域内。我不确定是否有更好的选择。
编辑:我们有一个您可能感兴趣的类似问题。 C#中如何检测鼠标是否在整个窗体和子控件内?
When the mouse leave event is fired one option is to check for the current position of the pointer and see if it within the form area. I am not sure whether a better option is available.
Edit: We have a similar question which might be of interest to you. How to detect if the mouse is inside the whole form and child controls in C#?
没有好的方法可以使 MouseLeave 对于容器控件来说可靠。用计时器解决这个问题:
There is no good way to make MouseLeave reliable for a container control. Punt this problem with a timer:
在您的用户控件上,为您的控件创建一个 mousehover 事件,如下所示(或其他事件类型),如下所示
在托管 UserControl 的 WinForm 上,UserControl 有此事件来处理 MouseOver,因此请将其放在您的 Designer.cs 中,该事件
调用此方法在您的 WinForm 上
,其中 ThumbImage 是用户控件的类型
On your user control create a mousehover Event for your control like this, (or other event type) like this
On your WinForm which hosts the UserControl have this for the UserControl to Handle the MouseOver so place this in your Designer.cs
Which calls this method on your WinForm
Where ThumbImage is the type of usercontrol