MouseButtonEventArgs 类

定义

为鼠标按钮相关事件提供数据。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
继承

示例

下面的示例创建一个鼠标按钮事件处理程序, 该处理程序更改引发事件的对象的颜色。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

注解

MouseButtonEventArgs与以下事件一起使用: MouseDownMouseUpMouseLeftButtonDownMouseLeftButtonUp MouseRightButtonDown 、、和对应的隧道事件MouseRightButtonUpMouseButtonEventArgs 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.

构造函数

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

属性

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.

(继承自 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.

(继承自 RoutedEventArgs)
LeftButton

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

(继承自 MouseEventArgs)
MiddleButton

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

(继承自 MouseEventArgs)
MouseDevice

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

(继承自 MouseEventArgs)
OriginalSource

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

(继承自 RoutedEventArgs)
RightButton

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

(继承自 MouseEventArgs)
RoutedEvent

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

(继承自 RoutedEventArgs)
Source

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

(继承自 RoutedEventArgs)
StylusDevice

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

(继承自 MouseEventArgs)
Timestamp

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

(继承自 InputEventArgs)
XButton1

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

(继承自 MouseEventArgs)
XButton2

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

(继承自 MouseEventArgs)

方法

Equals(Object)

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

(继承自 Object)
GetHashCode()

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

(继承自 Object)
GetPosition(IInputElement)

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

(继承自 MouseEventArgs)
GetType()

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

(继承自 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.

(继承自 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.

(继承自 RoutedEventArgs)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅