MouseWheelEventArgs.Delta プロパティ

定義

マウス ホイールが変化した量を示す値を取得します。

public:
 property int Delta { int get(); };
public int Delta { get; }
member this.Delta : int
Public ReadOnly Property Delta As Integer

プロパティ値

ホイールが変更された量。 この値は、マウス ホイールが上方に (ユーザーから離れる方向に) 回される場合に正の値になり、マウス ホイールが下方に (ユーザーに向かって) 回される場合に負の値になります。

次の例では、TextBoxマウス ホイールが正の場合は を上に移動し、マウス ホイールDeltaDeltaが負のTextBox場合は下に移動します。 TextBoxは にCanvasアタッチされます。

// 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);
        }
    }
}
' Moves the TextBox named box when the mouse wheel is rotated.
' The TextBox is on a Canvas named MainCanvas.
Private Sub MouseWheelHandler(ByVal sender As Object, ByVal e As MouseWheelEventArgs)
    ' If the mouse wheel delta is positive, move the box up.
    If e.Delta > 0 Then
        If Canvas.GetTop(box) >= 1 Then
            Canvas.SetTop(box, Canvas.GetTop(box) - 1)
        End If
    End If

    ' If the mouse wheel delta is negative, move the box down.
    If e.Delta < 0 Then
        If (Canvas.GetTop(box) + box.Height) <= MainCanvas.Height Then
            Canvas.SetTop(box, Canvas.GetTop(box) + 1)
        End If
    End If

End Sub

注釈

この値の有効な上限と下限の範囲は、デバイス実装またはイベントを発生させた他の呼び出し元から取得される可能性があるため、定義されていません。

適用対象

こちらもご覧ください