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 提供用於判斷滑鼠狀態的其他屬性和方法。