Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MouseWheel, determining up and down scrolling events

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

like image 537
Craig Avatar asked Mar 04 '10 10:03

Craig


People also ask

Why is my scroll wheel making me look up and down?

This is because mouse scroll wheel jumps up and down sometimes if the wheel speed is set up too high.

How does a mouse detect scrolling?

The scroll wheel at the front of the mouse is mounted on a switch mechanism that detects both how much it's rotated and whether you've pressed it (it functions like the central button of a conventional mouse). Rotations of the scroll wheel can be detected in a variety of different ways.

Which event is called when a mouse wheel scrolls?

The onwheel event occurs when the mouse wheel is rolled up or down over an element. The onwheel event also occurs when the user scrolls or zooms in or out of an element by using a touchpad (like the "mouse" of a laptop).


1 Answers

Check the Delta property of the MouseEventArgs:

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
like image 151
M.A. Hanin Avatar answered Sep 16 '22 22:09

M.A. Hanin