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.

示例

下面的示例在鼠标滚轮为正值的情况下移动附加到的,如果鼠标滚轮为负数,则将 TextBox Canvas Delta TextBox 向下移动 DeltaThe 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. 这些路由事件转发前面列出的附加事件,使其更易于访问 WPF 中的常规元素模型。These routed events forward the previously listed attached events to make them more accessible to the general element model in WPF.

附加事件和基本元素路由事件共享其事件数据,路由事件的冒泡和隧道版本也共享事件数据。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.

Delta如果向下移动鼠标滚轮 (远离) 用户,则属性为正; 如果鼠标滚轮向下移动 (朝向用户) ,则为负。The 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.

适用于

另请参阅