Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MouseButtonEventArgs.ClickCount Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the number of times the button was clicked.

Namespace:   System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

public int ClickCount { get; internal set; }

Property Value

Type: System.Int32

The number of times the mouse button was clicked.

One use of ClickCount is to determine whether a double mouse click has occurred. Some classes expose events for a double-click, such as the MouseDoubleClick event on the Control class. 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.

The following example creates a MouseButtonEventHandler which determines if a single, double, or triple click occurred. 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";
    }
}

.NET Framework
Available since 3.0
Silverlight
Available since 5.0
Return to top
Show:
© 2018 Microsoft