Windows 窗体:捕获 MouseWheel
我有一个 Windows 窗体(在 C#.NET 中工作)。
该表单的顶部有几个面板,底部有一些 ComboBox 和 DataGridView。
我想使用顶部面板上的滚动事件,但如果选择例如组合框,焦点就会丢失。这些面板包含各种其他控件。
当鼠标悬停在任何面板上时,如何才能始终接收鼠标滚轮事件? 到目前为止,我尝试使用 MouseEnter / MouseEnter 事件,但没有成功。
I have a Windows Form (working in C#.NET).
The form has a couple of panels top-side and some ComboBoxes and DataGridViews bottom-side.
I want to use the scroll events on the top-side panels, but if selecting a e.g. ComboBox the focus is lost. The panels contain various other controls.
How could I always receive the mouse wheel events when the mouse is over any of the panels ?
So far I tried to use the MouseEnter / MouseEnter events but with no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所描述的内容听起来像是您想要复制 Microsoft Outlook 等功能,您不需要实际单击来聚焦控件即可使用鼠标滚轮。
这是一个需要解决的相对高级的问题:它涉及实现包含表单的 IMessageFilter 接口,查找 WM_MOUSEWHEEL 事件并将它们定向到鼠标悬停在其上的控件。
这是一个示例(来自 这里):
请注意,此代码对应用程序中的所有表单都有效,而不仅仅是主表单。
What you describe sounds like you want to replicate the functionality of for example Microsoft Outlook, where you don't need to actually click to focus the control to use the mouse wheel on it.
This is a relatively advanced problem to solve: it involves implementing the
IMessageFilter
interface of the containing form, looking forWM_MOUSEWHEEL
events and directing them to the control that the mouse is hovering over.Here's an example (from here):
Note that this code is active for all the forms in your application, not just the main form.
每个控件都有一个鼠标滚轮事件,当控件具有焦点时鼠标滚轮移动时会发生该事件。
查看以下内容以获取更多信息:Control.MouseWheel 事件
Every control has a mousewheel event that occurs when the mouse wheel moves while the control has focus.
Check this out for more info: Control.MouseWheel Event