共用方式為


MouseButtonEventArgs.ClickCount 屬性

定義

取得按鍵被按一下的次數。

public:
 property int ClickCount { int get(); };
public int ClickCount { get; }
member this.ClickCount : int
Public ReadOnly Property ClickCount As Integer

屬性值

滑鼠按鍵被按一下的次數。

範例

下列範例會建立 , MouseButtonEventHandler 判斷是否發生單一、按兩下或三次按兩下。 ClickCount 屬性是用來判斷點擊次數。

private void OnMouseDownClickCount(object sender, MouseButtonEventArgs e)
{
    // Checks the number of clicks.
    if (e.ClickCount == 1)
    {
        // Single Click occurred.
        lblClickCount.Content = "Single Click";
    }
    if (e.ClickCount == 2)
    {
        // Double Click occurred.
        lblClickCount.Content = "Double Click";
    }
    if (e.ClickCount >= 3)
    {
        // Triple Click occurred.
        lblClickCount.Content = "Triple Click";
    }
}
Private Sub OnMouseDownClickCount(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    ' Checks the number of clicks.
    If e.ClickCount = 1 Then
        ' Single Click occurred.
        lblClickCount.Content = "Single Click"
    End If
    If e.ClickCount = 2 Then
        ' Double Click occurred.
        lblClickCount.Content = "Double Click"
    End If
    If e.ClickCount >= 3 Then
        ' Triple Click occurred.
        lblClickCount.Content = "Triple Click"
    End If
End Sub

備註

ClickCount 其中一個用法是判斷是否已發生按兩下。 某些類別會公開按兩下的事件,例如 MouseDoubleClick 類別上的 Control 事件。 當類別上未公開按兩下事件時,可以使用事件資料上的屬性來 ClickCount 偵測按兩下。

適用於

另請參閱