MouseWheelEventArgs.Delta Property

Definition

Gets a value that indicates the amount that the mouse wheel has changed.

C#
public int Delta { get; }

Property Value

The amount the wheel has changed. This value is positive if the mouse wheel is rotated in an upward direction (away from the user) or negative if the mouse wheel is rotated in a downward direction (toward the user).

Examples

The following example moves a TextBox up if the mouse wheel Delta is positive and moves the TextBox down if the mouse wheel Delta is negative. The TextBox is attached to a Canvas.

C#
// Moves the TextBox named box when the mouse wheel is rotated.
// The TextBox is on a Canvas named MainCanvas.
private void MouseWheelHandler(object sender, MouseWheelEventArgs e)
{
    // If the mouse wheel delta is positive, move the box up.
    if (e.Delta > 0)
    {
        if (Canvas.GetTop(box) >= 1)
        {
            Canvas.SetTop(box, Canvas.GetTop(box) - 1);
        }
    }

    // If the mouse wheel delta is negative, move the box down.
    if (e.Delta < 0)
    {
        if ((Canvas.GetTop(box) + box.Height) <= (MainCanvas.Height))
        {
            Canvas.SetTop(box, Canvas.GetTop(box) + 1);
        }
    }
}

Remarks

The effective upper and lower ranges of this value potentially come from device implementations or other callers that raised the event, and are therefore not defined.

Applies to

Produkt Versioner
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also