MouseButton 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义用于指定鼠标设备上的按钮的值。
public enum class MouseButton
public enum MouseButton
type MouseButton =
Public Enum MouseButton
- 继承
字段
Left | 0 | 鼠标左按钮。 |
Middle | 1 | 鼠标中键。 |
Right | 2 | 鼠标右按钮。 |
XButton1 | 3 | 第一个鼠标扩展按钮。 |
XButton2 | 4 | 第二个鼠标扩展按钮。 |
示例
以下示例创建一个 MouseDown 事件处理程序,该事件处理程序使用 MouseButton 枚举来确定按下了哪个按钮。 根据按下的按钮,触发事件的控件的背景会更改。
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