Windows 窗体上的鼠标离开事件
我已经在 Windows 窗体上设置了“鼠标离开”事件,并且想在鼠标离开可见区域时隐藏窗体。
但这是我面临问题的地方。即使当我将鼠标移动到同一窗体上的按钮时,它也会调用“鼠标离开”事件,这使得该窗体不可见。
这意味着我必须防止将鼠标移动到按钮时触发事件。但如何呢? 还有其他方法吗?
I've set the 'mouse leave' event on a windows form and I want to hide the form when the mouse leaves the visible area.
But here is where I am facing a problem. Even when I move the mouse to a button on the same form, it calls the 'mouse leave' event, which makes this form invisible.
It means I've got to prevent the event triggering when moving the mouse to the button. But how?
Any other approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有简单的方法可以做到这一点。一种方法可能是检查窗体内的所有控件,如果鼠标不在其中任何一个上,则意味着鼠标位于窗体之外
另一种方法可能是检查鼠标离开事件内部鼠标是否位于窗口边界内
There is no simple way to do it. One way could be to check all the controls inside the Form and if mouse is not over any of them this means mouse is outside the Form
Another way could be to check inside mouse leave event whether mouse is inside the window boundary or not
非常简单...添加以下内容:
it's very simple...add this: