Click here to Skip to main content
12,632,959 members (34,616 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: WPF Mouse
I searched MSDN for e.ClickCount, and it provieds the following eg.:
<textblock x:name="tb" text="" background="Black" foreground="White" />

and the code behind:
public partial class Window1 : Window
     {
         public Window1()
         {
             InitializeComponent();
 
            this.tb.MouseDown += new MouseButtonEventHandler(tb_MouseDown);
         }
 
        void tb_MouseDown(object sender, MouseButtonEventArgs e)
         {
             // Checks the number of clicks. 
            if (e.ClickCount == 1)
             {
                 // Single Click occurred.
                 this.tb.Text = "Single Click";
 
                DoSomethingForClick();            

            }
             if (e.ClickCount == 2)
             {
                 // Double Click occurred.
                 this.tb.Text += "Double Click";
 
               DoAnotherForDoubleClick();            

             }
             if (e.ClickCount >= 3)
             {
                 // Triple Click occurred.
                 this.tb.Text += "Triple Click";
             }
 
        }
     }


But what I want to get is like this:

(1)When I click once at one time, then execute DoSomethingForClick(). This has no problem!

(2)When I click twice at one time, then only execute DoAnotherForDoubleClick(). NOT firstly execute DoSomethingForClick() and then execute DoAnotherForDoubleClick() like in the MSDN eg., because tb_MouseDown fired 2 times;

How can I do?
Posted 25-Sep-12 16:07pm
Updated 26-Sep-12 0:30am
v4
Comments
Sergey Alexandrovich Kryukov 25-Sep-12 21:23pm
   
I'm sure you can do it, but why? Imagine the confusion of the user. Can you always distinguish it by yourself what it was: two separate clicks or a double click? I would rather review the conception of your UI and usability.
--SA

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I think your problem is caused by the system sending the following stream of messages for each 'double click' (check 'WM_LBUTTONDBLCLK' on msdn).

WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK -- Second WM_LBUTTONDOWN replaced
WM_LBUTTONUP
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161208.2 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100