MouseWheelEventHandler 代理人

定義

代表將處理 MouseWheelMouseWheel 路由事件,以及相關的附加事件和預覽事件的方法。Represents the method that will handle the MouseWheel and MouseWheel routed events, as well as related attached and Preview events.

public delegate void MouseWheelEventHandler(System::Object ^ sender, MouseWheelEventArgs ^ e);
public delegate void MouseWheelEventHandler(object sender, MouseWheelEventArgs e);
type MouseWheelEventHandler = delegate of obj * MouseWheelEventArgs -> unit
Public Delegate Sub MouseWheelEventHandler(sender As Object, e As MouseWheelEventArgs)

參數

sender
Object

附加事件處理常式的物件。The object where the event handler is attached.

e
MouseWheelEventArgs

事件資料。The event data.

繼承
MouseWheelEventHandler

範例

下列範例TextBox會將連接到的Canvas(如果滑鼠滾輪Delta是正數, 則會向上移動), 而如果TextBox滑鼠滾輪Delta是負值, 則會向下移動。The following example moves a TextBox, which is attached to a Canvas, upward if the mouse wheel Delta is positive and moves the TextBox downward if the mouse wheel Delta is negative.

// 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

備註

這個委派會與下列附加事件搭配使用。This delegate is used with the following attached events.

這個委派會與下列路由事件搭配使用。This delegate is used with the following routed events. 這些路由事件會轉送先前列出的附加事件, 讓中WPFWPF的一般元素模型更容易存取。These routed events forward the previously listed attached events to make them more accessible to the general element model in WPFWPF.

附加事件和基底元素路由事件會共用其事件資料, 而路由事件的反升和通道版本也會共用事件資料。The attached events and the base element routed events share their event data, and the bubbling and tunneling versions of the routed events also share event data. 這可能會影響事件在移動事件路由時的已處理特性。This can affect the handled characteristics of the event as it travels the event route. 如需詳細資訊, 請參閱輸入總覽For details, see Input Overview.

如果滑鼠滾輪向前移動 (遠離使用者), 則屬性為正數;如果滑鼠滾輪向下移動(朝向使用者),則為負數。DeltaThe Delta property is positive if the mouse wheel is moved forward (away from the user) or negative if the mouse wheel is moved downward (toward the user).

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。Gets an object that represents the method represented by the specified delegate.

適用於

另請參閱