This documentation is archived and is not being maintained.
MouseButton Enumeration
Visual Studio 2008
Defines values that specify the buttons on a mouse device.
Assembly: PresentationCore (in PresentationCore.dll)
The following example creates a MouseDown event handler that uses the MouseButton enumeration to determine which button was pressed. Depending on which button was pressed, the background of the control that fired the event is changed.
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; } } }
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: