问题描述
我想将鼠标悬停在图片框(或所有图片和主窗体)上,并使用鼠标滚轮滚动.但是我没有运气.我写了pictureBox1.MouseWheel并检查了增量.我设置了一个当它!= 0时的断点.到目前为止,无论我做什么,我都无法发生任何事情.我也尝试过mousemove,但这没有用.但是,中断if语句是可行的.我就是永远无法运转.
I want to hover over a picturebox (or all pics and the main form) and use the mousewheel to scroll. However i have no luck. I wrote pictureBox1.MouseWheel and check the delta. I set a breakpoint for when it != 0. So far no matter what i did i couldnt get anything to happen. I tried mousemove as well and that didnt work. However breaking on the if statement works. I just can never get the wheel to work.
如何使Picturebox(或窗体中的任何控件)调用鼠标滚轮事件?
How do i make picturebox (or any control in the form) call a mousewheel event?
-edit-没关系.大多数情况下,我已将事件添加到具有事件的对象中.效果很好.我不确定为什么我在写这个问题之前没有想到这个.我仍然愿意将鼠标悬停在+滚轮解决方案上.
-edit- nevermind. I added the event to the object that has the event most of the time. It works pretty well. I am not sure why i didnt think of this before i wrote this question. I am still open to mouse over + wheel solutions.
推荐答案
Windows不会将鼠标滚动消息发送到悬停的控件,而是转到具有焦点的控件.您已经知道如何固定焦点.
Windows doesn't send the mouse scroll message to the control that's hovered, it goes to the control with the focus. You already know how to fix the focus.
由于浏览器和Office程序的工作方式,此行为变得不直观.您可以在此线程.请注意,它可以在您应用程序的 any 窗口中运行.如果不希望,则必须在句柄值上添加过滤.
This behavior is getting unintuitive because of the way browsers and Office programs work. You'll find code to alter this in my answer in this thread. Beware that it works on any window in your app. You'll have to add filtering on the handle value if that's undesirable.
更新:此行为在Win10中已更改.它有一个新的系统设置,默认为当我将鼠标悬停在非活动窗口上时滚动它们".因此,焦点不再重要,它现在的工作原理与浏览器中的行为非常相似.测试您的应用程序很重要,您可以通过暂时禁用系统选项来查看在旧版Windows上会发生什么.
UPDATE: this behavior was changed in Win10. It has a new system setting named "Scroll inactive windows when I hover over them", turned on by default. So focus no longer matters and it now works very similar to way it behaves in a browser. Testing your app is important, you can see what happens on an older version of Windows by temporarily disabling the system option.
这篇关于PictureBox的MouseWheel事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!