MouseButtonEventArgs.ClickCount 属性

定义

获取单击此按钮的次数。Gets the number of times the button was clicked.

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

属性值

Int32

单击此鼠标按钮的次数。The number of times the mouse button was clicked.

示例

下面的示例创建一个 MouseButtonEventHandler ,它确定是发生了单个、双重还是三次单击。The following example creates a MouseButtonEventHandler which determines if a single, double, or triple click occurred. ClickCount 属性用于确定点击数。ClickCount property is used to determine the number of clicks.

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 是确定是否发生了双击鼠标。One use of ClickCount is to determine whether a double mouse click has occurred. 某些类公开双击事件,例如 MouseDoubleClick 类的事件 ControlSome classes expose events for a double-click, such as the MouseDoubleClick event on the Control class. 在类上未公开双击事件时,可以使用 ClickCount 事件数据的属性检测双击。When a double click event is not exposed on a class, a double click can be detected by using the ClickCount property on the event data.

适用于

另请参阅