MouseButtonEventArgs Class

Definition

为鼠标按钮相关事件提供数据。Provides data for mouse button related events.

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

Examples

下面的示例创建一个鼠标按钮事件处理程序,该处理程序更改引发事件的对象的颜色。The following example creates a mouse button event handler that changes the color of the object that raised the event. 选择的颜色取决于按下的鼠标按钮。The color chosen depends on the mouse button which was pressed. 将检查 ChangedButton 属性以确定按下的按钮。The ChangedButton property is checked to determine which button was pressed.

private void MouseButtonDownHandler(object sender, MouseButtonEventArgs e)
{
    Control src = e.Source as Control;

    if (src != null)
    {
        switch (e.ChangedButton)
        {
            case MouseButton.Left:
                src.Background = Brushes.Green;
                break;
            case MouseButton.Middle:
                src.Background = Brushes.Red;
                break;
            case MouseButton.Right:
                src.Background = Brushes.Yellow;
                break;
            case MouseButton.XButton1:
                src.Background = Brushes.Brown;
                break;
            case MouseButton.XButton2:
                src.Background = Brushes.Purple;
                break;
            default:
                break;
        }
    }
}
Private Sub MouseButtonDownHandler(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    Dim src As Control = TryCast(e.Source, Control)

    If src IsNot Nothing Then
        Select Case e.ChangedButton
            Case MouseButton.Left
                src.Background = Brushes.Green
            Case MouseButton.Middle
                src.Background = Brushes.Red
            Case MouseButton.Right
                src.Background = Brushes.Yellow
            Case MouseButton.XButton1
                src.Background = Brushes.Brown
            Case MouseButton.XButton2
                src.Background = Brushes.Purple
            Case Else
        End Select
    End If
End Sub

Remarks

MouseButtonEventArgs 与以下事件一起使用: MouseDownMouseUpMouseLeftButtonDownMouseLeftButtonUpMouseRightButtonDownMouseRightButtonUp和对应的隧道事件。MouseButtonEventArgs is used with the following events: MouseDown, MouseUp, MouseLeftButtonDown, MouseLeftButtonUp, MouseRightButtonDown, MouseRightButtonUp, and the corresponding tunneling events.

Mouse 类提供了用于确定鼠标状态的附加属性和方法。The Mouse class provides additional properties and methods for determining the state of the mouse.

Constructors

MouseButtonEventArgs(MouseDevice, Int32, MouseButton)

使用指定的 MouseButtonEventArgs、时间戳和 MouseDevice 初始化 MouseButton 类的新实例。Initializes a new instance of the MouseButtonEventArgs class by using the specified MouseDevice, timestamp, and MouseButton.

MouseButtonEventArgs(MouseDevice, Int32, MouseButton, StylusDevice)

使用指定的 MouseButtonEventArgs、时间戳、MouseDeviceMouseButton 初始化 StylusDevice 类的新实例。Initializes a new instance of the MouseButtonEventArgs class by using the specified MouseDevice, timestamp, MouseButton, and StylusDevice. ..

Properties

ButtonState

获取与该事件关联的按钮的状态。Gets the state of the button associated with the event.

ChangedButton

获取与该事件关联的按钮。Gets the button associated with the event.

ClickCount

获取单击此按钮的次数。Gets the number of times the button was clicked.

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