getting system's double click timer interval in WPF (value from control panel)
Asked Answered
I

4

6

I have a FrameworkElement and I want to perform action A when the user single clicks, and action B when the user double clicks.

Due to the way events are delivered, I always get a single click event which begins action A. After looking around, I found an interesting technique here using a timer to delay the handling of the clicks. However, this example hardcodes the timer to 300 milliseconds, but I would prefer to use the user's "Double-click speed" setting Control Panel's Mouse Properties dialog.

What's the wpf/C# API for getting that value from the system?

Intransigent answered 27/1, 2011 at 15:47 Comment(0)
S
10

You can find the time here: System.Windows.Forms.SystemInformation.DoubleClickTime

You can actually see a full implementation of what you are trying to achieve here:

WPF: Button single click + double click issue

Sloe answered 27/1, 2011 at 15:54 Comment(7)
good, but better to use SystemInformation.DoubleClickTime and avoid the winforms reference in WPFVardon
Which SystemInformation class are you referring to? what is its namespace?Sloe
@Muad'Dib it looks like SystemInformation is part of winformsIntransigent
@Sloe Thanks! This gives exactly what I want (not concerned about the winforms reference :)..Intransigent
@Shezan Baig I was thinking of the SystemParamaters class, which is NOT part of winforms. Turns out, there is not double-click info in there. I've used it for things like mouse move threshold for drag n drop.Vardon
To avoid the reference to Winforms, you could just do the same thing it does behind the scenes and import the GetDoubleClickTime function in user32.dll: [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]public static extern int GetDoubleClickTime();Quieten
@KentBoogaart You should post that as answer, because it doesn't use Winforms (the author requested WPF) unlike the other answers.Append
K
7

If you don't want reference System.Windows.Forms assembly, you can try this:

    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern int GetDoubleClickTime();
Kyphosis answered 26/8, 2017 at 2:48 Comment(0)
E
4

This should work SystemInformation.DoubleClickTime

Electoral answered 27/1, 2011 at 15:56 Comment(0)
L
0

I have a FrameworkElement and I want to perform action A when the user single clicks, and action B when the user double clicks.

If you're handling an event that provides a MouseButtonEventArgs, such as UIElement.MouseLeftButtonDown, you can access MouseButtonEventArgs.ClickCount to determine if multiple clicks have happened within the double-click time of each other. Since FrameworkElement derives from UIElement this should be possible in your case.

No need to use DllImport or WinForms, as you don't really need to know the double-click time to accomplish your main goal.

Edit add: I discovered that this only really works for the ButtonDown events (left or right). I'm not sure why they didn't implement this properly for the ButtonUp events, but it should suffice to catch both events, and keep a member variable of the ClickCount from the ButtonDown that you can check when receiving ButtonUp.

Luminous answered 21/3, 2018 at 21:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.