如何在显示 ContextMenuStrip 时接收鼠标移动事件?
当用户将鼠标悬停在表格中的单元格上时,我使用 ContextMenuStrip 向用户显示一些选项,方法是从内部调用其 Show(Control, int, int) 方法表的 MouseMove
事件,将表作为 Control 参数传入。
如果应用程序未激活,一切都会按预期运行;但如果应用程序处于活动状态,则一旦显示 ContextMenuStrip
,MouseMove
事件就会停止触发。
如何在显示 ContextMenuStrip 时接收鼠标移动事件?我不想添加挂钩或应用程序过滤器,我只想要非活动应用程序行为,即使应用程序处于活动状态也是如此。
I'm using a ContextMenuStrip
to show some options to the user when they mouse over cells in a table, by calling its Show(Control, int, int)
method from within a the table's MouseMove
event, passing the table in as the Control parameter.
If the app isn't active, everything works as intended; but if the app is active, then the MouseMove
events stop firing once the ContextMenuStrip
is shown.
How do I receive mouse move events while showing a ContextMenuStrip? I don't want to add hooks or an application filter, I just want the inactive-app behaviour even when the app is active.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不仅仅是鼠标捕获,这很容易解决。有一个名为“ModalMenuFilter”的内部类,当显示过滤各种消息的工具条下拉列表时会激活该类。包括WM_MOUSEMOVE。它通过使用 SetWindowsHookEx() 来完成此操作。当您的应用程序未处于活动状态时它会起作用,因为仅当您的表单处于活动状态时才会安装此挂钩。
这些都无法从您的代码中访问,您必须使用反射。在我看来,您可以使用 ModalMenuFilter.RemoveActiveToolStrip() 来禁用过滤器。用 Reflector 看一下。然而,这很可能会导致其他问题。
It is not just a mouse capture, that would be easy to work around. There's an internal class named "ModalMenuFilter" that is activated when a toolstrip dropdown is displayed that filters various messages. Including WM_MOUSEMOVE. It does this by using SetWindowsHookEx(). It works when your app isn't active because this hook is only installed when your form is active.
None of this is accessible from your code, you'd have to use Reflection. Looks to me that you can use ModalMenuFilter.RemoveActiveToolStrip() to disable the filter. Have a look-see with Reflector. This more than likely causes other problems however.
这是不可能的,当显示上下文菜单条时,菜单窗口捕获鼠标
that's not possible, when the context menu strip is shown, the menu windows captures the mouse