MouseWheelEventArgs Class

Definition

为报告鼠标设备的鼠标滚轮增量值更改的各事件提供数据。Provides data for various events that report changes to the mouse wheel delta value of a mouse device.

public ref class MouseWheelEventArgs : System::Windows::Input::MouseEventArgs
public class MouseWheelEventArgs : System.Windows.Input.MouseEventArgs
type MouseWheelEventArgs = class
    inherit MouseEventArgs
Public Class MouseWheelEventArgs
Inherits MouseEventArgs
Inheritance

Examples

下面的示例在鼠标滚轮 Delta 为正时将 TextBox 向上移动,如果鼠标滚轮 Delta 为负,则将 TextBox 向下移动。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. TextBox 附加到 CanvasThe TextBox is attached to a 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

Remarks

MouseWheelEventArgs 与以下事件一起使用:MouseWheelEventArgs is used with the following events:

如果鼠标滚轮向上或向下移动(远离用户),则 Delta 属性为正; 如果鼠标滚轮向下或向后移动(朝向用户),则为负。The Delta property is positive if the mouse wheel is moved upward or forward (away from the user) or negative if the mouse wheel is moved downward or backward (toward the user).

即使鼠标滚轮移动发生,也会引发此事件。This event is raised even for small mouse wheel movements. 在某些情况下,适合通过检查增量是否超出特定阈值来实现可限制小鼠标滚轮增量的处理程序。For some scenarios, it is appropriate to implement handlers that throttle small mouse wheel deltas by checking whether the delta exceeds a certain threshold. 否则,你可能会在鼠标滚轮增量较小的情况下调用你的处理程序,这种情况下,与鼠标滚轮移动关联的任何 UI 都不会更新。Otherwise, you might invoke your handler for cases where the mouse wheel delta was so small that any UI that is tied to the mouse wheel movement would not update. 确切地说明如何在处理程序中实现阈值行为,该阈值应该是完全特定于实现的。Exactly how you implement the threshold behavior in a handler and what that threshold should be is entirely implementation-specific.

Constructors

MouseWheelEventArgs(MouseDevice, Int32, Int32)

初始化 MouseWheelEventArgs 类的新实例。Initializes a new instance of the MouseWheelEventArgs class.

Properties

Delta

获取指示鼠标滚轮变更量的值。Gets a value that indicates the amount that the mouse wheel has changed.

Device

获取启动此事件的输入设备。Gets the input device that initiated this event.

(Inherited from InputEventArgs)
Handled

获取或设置一个值,该值指示针对路由事件(在其经过路由时)的事件处理的当前状态。Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.

(Inherited from RoutedEventArgs)
LeftButton

获取鼠标左键的当前状态。Gets the current state of the left mouse button.

(Inherited from MouseEventArgs)
MiddleButton

获取鼠标中键的当前状态。Gets the current state of the middle mouse button.

(Inherited from MouseEventArgs)
MouseDevice

获取与此事件关联的鼠标设备。Gets the mouse device associated with this event.

(Inherited from MouseEventArgs)
OriginalSource

在父类进行任何可能的 Source 调整之前,获取由纯命中测试确定的原始报告源。Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.

(Inherited from RoutedEventArgs)
RightButton

获取鼠标右键的当前状态。Gets the current state of the right mouse button.

(Inherited from MouseEventArgs)
RoutedEvent

获取或设置与此 RoutedEventArgs 实例关联的 RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance.

(Inherited from RoutedEventArgs)
Source

获取或设置对引发事件的对象的引用。Gets or sets a reference to the object that raised the event.

(Inherited from RoutedEventArgs)
StylusDevice

获取与此事件关联的触笔设备。Gets the stylus device associated with this event.

(Inherited from MouseEventArgs)
Timestamp

获取此事件发生时的时间。Gets the time when this event occurred.

(Inherited from InputEventArgs)
XButton1

获取第一个鼠标扩展按钮的当前状态。Gets the current state of the first extended mouse button.

(Inherited from MouseEventArgs)
XButton2

获取第二个鼠标扩展按钮的当前状态。Gets the state of the second extended mouse button.

(Inherited from MouseEventArgs)

Methods

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetPosition(IInputElement)

返回相对于指定元素的鼠标指针位置。Returns the position of the mouse pointer relative to the specified element.

(Inherited from MouseEventArgs)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InvokeEventHandler(Delegate, Object)

以特定于类型的方式调用事件处理程序,这样做可以提高事件系统效率。Invokes event handlers in a type-specific way, which can increase event system efficiency.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnSetSource(Object)

在派生类中重写时,每当实例的 Source 属性的值发生更改,则提供一个通知回调入口点。When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes.

(Inherited from RoutedEventArgs)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also