CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2001
    Posts
    28

    How to identify a single click with a double click in C#

    Hello all,

    I am currently working in a project that is developed based .NET FrameWork, recently I have faced with a problem is how to identify a single click with a double click in C#. Anyone can share your experience with us?

    Thank in advance

  2. #2
    Join Date
    Jul 2003
    Location
    Linz,Austria
    Posts
    48
    Hi,


    if you need it for window-forms or other elements you can add
    mouse-event-handler like the DoubleClick-Event-handler or MouseDown-Event-Handler;

    you can add this things with the properties if you use .NET Studio from Microsoft ( klick onto the icon with the yellow flash, search the right event you need, doubleclick on it and the handler will be created automatically ).


    have a nice day and blue skies

  3. #3
    Join Date
    Oct 2001
    Posts
    28
    Hello,
    :-), I suspect you thought me as a newbie. In .NET (C#), before the DoubleClick event occurred, then the Click event fired off, so the question I want to ask is, how to handle this case.

  4. #4
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    55°50' N 37°39' E
    Posts
    1,503

    i wonder

    I wonder why people use Click events when there is such a beautiful thing named MouseDown and MouseUp. I never use click.
    so, it will solve your problem too...
    but i hope there are other ways out too... but no known to me.
    sowwy!
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

  5. #5
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    55°50' N 37°39' E
    Posts
    1,503

    forgot to tell you

    that mouseeventargs have a parameter named "Clicks"...

    catch the bird...
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

  6. #6
    Join Date
    Jul 2006
    Posts
    97

    Re: How to identify a single click with a double click in C#

    Hi, I hope it's ok bumping the thread, since I have the same problem.

    I have a treeview and don't want the Click event to be fired when treeview is doubleclicked. Unfortunately, neither MouseUp, nor MouseEventArgs.Clicks don't help me.

    Maybe someone can help me?
    Thanks.
    Using .NET 2.0

  7. #7
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: How to identify a single click with a double click in C#

    Quote Originally Posted by gecka
    Hi, I hope it's ok bumping the thread, since I have the same problem.

    I have a treeview and don't want the Click event to be fired when treeview is doubleclicked. Unfortunately, neither MouseUp, nor MouseEventArgs.Clicks don't help me.

    Maybe someone can help me?
    Thanks.
    Maybe you can use MoudeDown event instead of MouseClick event and there you can check for doubleClicks
    Code:
    private void textBox1_MouseDown(object sender, MouseEventArgs e) {
    	if (e.Clicks > 1) {
    		return;
       } 
       // your code you normally would do in the clickevent comes here
    }
    Hopefully this helps
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured