MouseButtonEventArgs.ButtonState 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得與事件關聯的按鍵狀態。
public:
property System::Windows::Input::MouseButtonState ButtonState { System::Windows::Input::MouseButtonState get(); };
public System.Windows.Input.MouseButtonState ButtonState { get; }
member this.ButtonState : System.Windows.Input.MouseButtonState
Public ReadOnly Property ButtonState As MouseButtonState
屬性值
按鍵的狀態。
範例
下列範例會建立滑鼠按鈕事件處理程式,以變更處理事件的物件色彩。 選擇的色彩取決於按下或放開滑鼠按鈕。
private void MouseButtonEventHandler(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
this.Background = Brushes.BurlyWood;
}
if (e.ButtonState == MouseButtonState.Released)
{
this.Background = Brushes.Ivory;
}
}
Private Sub MouseButtonEventHandler(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
If e.ButtonState = MouseButtonState.Pressed Then
Me.Background = Brushes.BurlyWood
End If
If e.ButtonState = MouseButtonState.Released Then
Me.Background = Brushes.Ivory
End If
End Sub
備註
類別 Mouse 提供用來判斷滑鼠狀態的其他屬性和方法。