Export (0) Print
Expand All

MouseButtonEventArgs.ClickCount Property

Updated: July 2010

Gets the number of times the button was clicked.

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

'Declaration
Public Property ClickCount As Integer
'Usage
Dim instance As MouseButtonEventArgs 
Dim value As Integer 

value = instance.ClickCount

instance.ClickCount = value
Members of this class are either not typically used in XAML, or cannot be used in XAML.

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";
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Date

History

Reason

July 2010

Corrected example.

Customer feedback.

Community Additions

ADD
Show:
© 2014 Microsoft