MouseButtonEventArgs.ChangedButton 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取与该事件关联的按钮。
public:
property System::Windows::Input::MouseButton ChangedButton { System::Windows::Input::MouseButton get(); };
public System.Windows.Input.MouseButton ChangedButton { get; }
member this.ChangedButton : System.Windows.Input.MouseButton
Public ReadOnly Property ChangedButton As MouseButton
属性值
按下的按钮。
示例
以下示例创建一个鼠标按钮事件处理程序,该处理程序根据按下的鼠标按钮更改对象的颜色。 检查 ChangedButton 属性以确定按下了哪个按钮。
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
注解
类 Mouse 提供用于确定鼠标状态的其他属性和方法。