MouseWheelEventHandler 委托

定义

表示将处理 MouseWheelMouseWheel 路由事件以及相关附加事件和预览事件的方法。

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

事件处理程序所附加到的对象。

e
MouseWheelEventArgs

事件数据。

示例

以下示例在鼠标滚轮为正数时向上移动TextBoxCanvas附加到 的 ,如果鼠标滚轮DeltaDelta为负数,则向下移动 TextBox

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

注解

此委托与以下附加事件一起使用。

此委托用于以下路由事件。 这些路由事件转发前面列出的附加事件,使其更易于 WPF 中的常规元素模型访问。

附加事件和基本元素路由事件共享其事件数据,路由事件的浮升和隧道版本也共享事件数据。 这可能会影响事件在事件路由中传输时处理的特征。 有关详细信息,请参阅 输入概述

Delta如果鼠标滚轮向前移动 (远离用户) ,则属性为正数;如果鼠标滚轮向下移动, (向用户) 方向移动,则属性为负数。

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。

适用于

另请参阅