9

I am handling a mouse wheel event in a UserControl which inherits NumericUpDown

Private Sub MyUpDown_MouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel
    Me.Value += e.Delta * Me.Increment ' / WHEEL_DELTA
End Sub

MouseEventArgs.Delta has this tooltip:

Gets a signed count of the number of detents the mouse wheel has rotated, multiplied by the WHEEL_DELTA constant. A detent is one notch of the mouse wheel.

However I can't find this constant. It is usually 120, but I don't want to bank on usually. How can I expose it to my code?

djv
  • 15,168
  • 7
  • 48
  • 72
  • possible duplicate of [Why is WheelDelta = 120?](http://stackoverflow.com/questions/7753123/why-is-wheeldelta-120) – LarsTech Feb 06 '14 at 20:55
  • @LarsTech If you can show me on that page how I can get this constant, I will agree. But I don't. – djv Feb 06 '14 at 21:01
  • `e.Delta` has the constant - whatever it may be - taken into consideration; its the result so why care? – Ňɏssa Pøngjǣrdenlarp Feb 06 '14 at 21:03
  • @Plutonix does it? e.Delta is 120 so does that mean I am scrolling 120 ticks? No. I need to divide by WHEEL_DELTA (120 in most cases). Right now my code is `Me.Value += e.Delta * Me.Increment / 120` but a different mouse may have a different WHEEL_DELTA <> 120 – djv Feb 06 '14 at 21:06
  • no, it means you scrolled 1 detent and WHEEL_DELTA is 120 in this case. e.Delta = ticks * WHEEL_DELTA (see your post). You'd only need WHEEL_DELTA if you were working backwards to determine ticks/detents, or doing something in WndProc – Ňɏssa Pøngjǣrdenlarp Feb 06 '14 at 21:10
  • @Plutonix so this code: `Me.Value += e.Delta * Me.Increment / 120` is ok? – djv Feb 06 '14 at 21:15
  • 4
    Use SystemInformation.MouseWheelScrollDelta – Hans Passant Feb 06 '14 at 21:30

1 Answers1

11

According to MSDN Most applications should check for a positive or negative value rather than an aggregate total. in most cases, I have only seen 1 detent movement per click - they might come in rapid succession, but 1 tick (e.Delta=120) per click.

To get the MouseWheel delata factor:

 WheelDelta As Integer = SystemInformation.MouseWheelScrollDelta

it is a member of System.Windows.Forms along with all sorts of other metrics like scroll thumb width etc.

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178