Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. click/doubleclick event paradox

click/doubleclick event paradox

Scheduled Pinned Locked Moved C#
questionhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Senkwe Chanda
    wrote on last edited by
    #1

    Hi guys, I hope there is a simple explanation, or a simple workaround for this... I need to capture both the click and double click events of a control. Depending on the event, the eventhandlers will do two totally different things. The problem is, it seems that if you subscribe to both events, you ALWAYS get a click event before you get a doubleclick event. Here's a little experiment I did when I got curious. Place a label on a form and set it's text property to "". Now add both a click and doubleclick event handler to the FORM. In the click event handler do the following

    label1.Text="SingleMouseClick"

    and in the doubleclick event handler...

    label1.Text+="DoubleMouseClick"

    Now, run the app and DOUBLE CLICK the form. I get the label spittig out SingleMouseClickDoubleMouseClick indicating that the click event code ran first. How can I get around this? I really want the events to be separate. James, I know you're listening...you must have a plan as usual :-) Regards Senkwe Just another wannabe code junky

    J 1 Reply Last reply
    0
    • S Senkwe Chanda

      Hi guys, I hope there is a simple explanation, or a simple workaround for this... I need to capture both the click and double click events of a control. Depending on the event, the eventhandlers will do two totally different things. The problem is, it seems that if you subscribe to both events, you ALWAYS get a click event before you get a doubleclick event. Here's a little experiment I did when I got curious. Place a label on a form and set it's text property to "". Now add both a click and doubleclick event handler to the FORM. In the click event handler do the following

      label1.Text="SingleMouseClick"

      and in the doubleclick event handler...

      label1.Text+="DoubleMouseClick"

      Now, run the app and DOUBLE CLICK the form. I get the label spittig out SingleMouseClickDoubleMouseClick indicating that the click event code ran first. How can I get around this? I really want the events to be separate. James, I know you're listening...you must have a plan as usual :-) Regards Senkwe Just another wannabe code junky

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Senkwe Chanda wrote: James, I know you're listening...you must have a plan as usual LOL, yep you got me :) The reason for having both events fire is to make the UI appear responsive, since the double-click time can be changed in the control panel you could have to wait up to a second or more before a click event would fire since it would have to wait to see if the second click ever occurred before firing the click event. whew, that was long winded :-P Now for the fix. Have your single click event handler enable a windows timer; have the double-click even disable that timer and do whatever you want. Inside of the tick event in the windows timer is where you would code the single-click stuff. You can obtain the maximum number of milliseconds that can elapse between clicks by reading the SystemInformation.DoubleClickTime property. To be even more thorough you need to also ensure that the second click occurs within a rectangle of size SystemInformation.DoubleClickSize from the first click. I highly recommend that you first set your double-click time way up; so you can see if this is going to be detrimental to the usability of your application. HTH, James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972

      S 1 Reply Last reply
      0
      • J James T Johnson

        Senkwe Chanda wrote: James, I know you're listening...you must have a plan as usual LOL, yep you got me :) The reason for having both events fire is to make the UI appear responsive, since the double-click time can be changed in the control panel you could have to wait up to a second or more before a click event would fire since it would have to wait to see if the second click ever occurred before firing the click event. whew, that was long winded :-P Now for the fix. Have your single click event handler enable a windows timer; have the double-click even disable that timer and do whatever you want. Inside of the tick event in the windows timer is where you would code the single-click stuff. You can obtain the maximum number of milliseconds that can elapse between clicks by reading the SystemInformation.DoubleClickTime property. To be even more thorough you need to also ensure that the second click occurs within a rectangle of size SystemInformation.DoubleClickSize from the first click. I highly recommend that you first set your double-click time way up; so you can see if this is going to be detrimental to the usability of your application. HTH, James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972

        S Offline
        S Offline
        Senkwe Chanda
        wrote on last edited by
        #3

        Thanks again James, that should work beautifully. Regards Senkwe Just another wannabe code junky

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups