vb.net MouseWheel,确定上下滚动事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2378296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:45:01  来源:igfitidea点击:

MouseWheel, determining up and down scrolling events

vb.neteventshandlermousewheel

提问by Craig

Is there any way to determine if the mouse scrolls up or down using the Mousewheel handler on a sub? eg

有什么方法可以使用子上的鼠标滚轮处理程序来确定鼠标是向上还是向下滚动?例如

Private Sub PictureBox1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel

if mousewheel.scrollup then
        UserZoom = UserZoom + 0.05
        Me.Refresh()
end if


End Sub

I want to be able to adjust the value of userzoom up or down according to if the mouse is wheeled up or down. Any help would be appreciated guys

我希望能够根据鼠标向上或向下滚动来向上或向下调整 userzoom 的值。任何帮助将不胜感激伙计们

回答by M.A. Hanin

Check the Delta property of the MouseEventArgs:

检查 MouseEventArgs 的 Delta 属性:

Sample code:

示例代码:

Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
    If e.Delta > 0 Then
        Trace.WriteLine("Scrolled up!")
    Else
        Trace.WriteLine("Scrolled down!")
    End If
End Sub

回答by Craig

Figured it out.

弄清楚了。

e.deltapasses either negative or positive values according to if the mouse is scrolled up or down!

e.delta根据鼠标向上或向下滚动传递负值或正值!