#677 – Why the Standard Mouse Wheel Delta is 120

For a standard Microsoft mouse, you’ll notice that the value of the MouseWheelEventArgs.Delta parameter is always either 120 when you turn the mouse wheel forward one click or -120 when you turn the mouse wheel backwards one click.  You might wonder why the value of 120 is used, rather than just 1 and -1 values.

The larger number for the mouse wheel delta is used for a typical mouse so that other manufacturers of mouse devices can include a mouse wheel with more precision, which could then return a smaller value for each delta.  For example, there might be twice as many click detents on a device, which could then return a delta value of 60.

The value of 120 can be evenly divided by 2, 3, 4 or 5.  This gives a mouse manufacturer more options in dividing up the current coarser clicks into an even number of higher resolution clicks.


#676 – MouseWheel Event Is Fired for Element That Mouse Pointer Is Over

When the user rotates the mouse wheel, the PreviewMouseWheel and MouseWheel events will fire.  The PreviewMouseWheel event tunnels down the logical tree, firing for the topmost element and working down to the element that the mouse pointer was located over when the mouse wheel was rotated.  The MouseWheel event then fires, bubbling up the logical tree and firing for each element until the topmost element is reached.

In the example below, if the user rotates the mouse wheel while the mouse pointer is over the Button, the event sequence is:

  • PreviewMouseWheel for Window
  • PreviewMouseWheel for StackPanel
  • PreviewMouseWheel for Button
  • MouseWheel for  Button
  • MouseWheel for StackPanel
  • MouseWheel for Window
<Window Name="win1" x:Class="WpfApplication1.MainWindow"
        Title="Mouse Wheel"
        Width="350" Height="200"
        MouseWheel="Window_MouseWheel" PreviewMouseWheel="Window_PreviewMouseWheel">

    <StackPanel MouseWheel="StackPanel_MouseWheel" PreviewMouseWheel="StackPanel_PreviewMouseWheel">
        <Label Content="Tiberius Julius Caesar Augustus" />
        <Button Content="Make Me Emperor" MouseWheel="Button_MouseWheel" PreviewMouseWheel="Button_PreviewMouseWheel"/>

#675 – Handling the PreviewMouseWheel and MouseWheel Events

Every user interface element defines the PreviewMouseWheel/MouseWheel event pair, which fire whenever the user interacts with the mouse wheel.

The PreviewMouseWheel event is a tunneling event, firing on each element of the logical tree, from the top down.  The corresponding MouseWheel event is bubbling, firing up the logical tree from the control where the event originated.

The mouse wheel events will fire once for each click of the mouse wheel.  The MouseWheelEventArgs.Delta property is meant to indicate the amount that the mouse wheel changed, but will in practice take on one of two values–a positive value when the mouse wheel is rotated forward (away from the user) and a negative value otherwise.

        private static int eventCount = 0;

        private void win1_MouseWheel(object sender, MouseWheelEventArgs e)
            Info = string.Format("Click #{0}, Delta = {1}", ++eventCount, e.Delta);

Rotating the wheel forward, we get a Delta of 120.

Rotating backward, we get -120.