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. avoid double click

avoid double click

Scheduled Pinned Locked Moved C#
help
13 Posts 4 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.
  • N neeraj max

    i have two panel in ma form. panel1 with button1 on it at location let say x:10,y:10 and panel2 with button 2 on it at location x:10,y:10. what actually button1 do:- it hide panel1 and shows panel2 at the same location. but whenever i click on button1 twice after completion its process it fire button2 click event, plz help me ASAP

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #2

    The problem is that the button click event is happening almost immediately - so the second "click" is going to the correct place - the control at that position on the "new" panel. And that will generate a click event for the new button because that is exactly what should happen. If you want to stop it, then 1) Create a class level variable:

    private DateTime lastSwap = DateTime.Now;

    1. In the Button1 click handler, set it:

    lastSwap = DateTime.Now;

    And then swap panels. 3) In the Button2 click handler, check it and ignore if too soon:

    if (DateTime.Now < lastSwap.AddMilliseconds(500)) return;

    You can change the 500 to any value you think reasonable - 500 provides half a second.

    If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    N 1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      The problem is that the button click event is happening almost immediately - so the second "click" is going to the correct place - the control at that position on the "new" panel. And that will generate a click event for the new button because that is exactly what should happen. If you want to stop it, then 1) Create a class level variable:

      private DateTime lastSwap = DateTime.Now;

      1. In the Button1 click handler, set it:

      lastSwap = DateTime.Now;

      And then swap panels. 3) In the Button2 click handler, check it and ignore if too soon:

      if (DateTime.Now < lastSwap.AddMilliseconds(500)) return;

      You can change the 500 to any value you think reasonable - 500 provides half a second.

      If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

      N Offline
      N Offline
      neeraj max
      wrote on last edited by
      #3

      hello, thaks for your quick response... code is working properly... but it is impossible to implement on big application where there are mre den 20,25 panels and every control takes diff diff tym to execute. hope you get my point. thanks once again.

      J 1 Reply Last reply
      0
      • N neeraj max

        hello, thaks for your quick response... code is working properly... but it is impossible to implement on big application where there are mre den 20,25 panels and every control takes diff diff tym to execute. hope you get my point. thanks once again.

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #4

        neeraj@max wrote:

        are mre den

        neeraj@max wrote:

        takes diff diff tym

        neeraj@max wrote:

        hope you get my point.

        No, not really. Try cutting out the childish txtspk and talk like a grown up.

        N 1 Reply Last reply
        0
        • J J4amieC

          neeraj@max wrote:

          are mre den

          neeraj@max wrote:

          takes diff diff tym

          neeraj@max wrote:

          hope you get my point.

          No, not really. Try cutting out the childish txtspk and talk like a grown up.

          N Offline
          N Offline
          neeraj max
          wrote on last edited by
          #5

          hello, thanks for your quick response... code is working properly... but it is impossible to implement on big application where there are more then 20,25 panels and every control takes different time to execute. hope you are getting my point. thanks once again.

          P J 2 Replies Last reply
          0
          • N neeraj max

            hello, thanks for your quick response... code is working properly... but it is impossible to implement on big application where there are more then 20,25 panels and every control takes different time to execute. hope you are getting my point. thanks once again.

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #6

            It's not impossible to implement, it's just going to take a while.

            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            1 Reply Last reply
            0
            • N neeraj max

              hello, thanks for your quick response... code is working properly... but it is impossible to implement on big application where there are more then 20,25 panels and every control takes different time to execute. hope you are getting my point. thanks once again.

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #7

              You're missing the point. As a programmer, when you find a solution to the problem, but you have 25 problems - you dont implement the solution 25 times. You implement it once and re-use it 25 times. Think of it this way - if you have 25 customers, you dont write 25 different classes to represent each customer, you implement once class called "Customer" and reuse it 25 times. The same thing applies here, you need a solution which stops a button being clicked within 500ms of another button (personally I think this is an awful solution to your original problem, but hey if it works for you go with it). Write a class which exhibits this behaviour and attach it to every button which requires it.

              N 1 Reply Last reply
              0
              • J J4amieC

                You're missing the point. As a programmer, when you find a solution to the problem, but you have 25 problems - you dont implement the solution 25 times. You implement it once and re-use it 25 times. Think of it this way - if you have 25 customers, you dont write 25 different classes to represent each customer, you implement once class called "Customer" and reuse it 25 times. The same thing applies here, you need a solution which stops a button being clicked within 500ms of another button (personally I think this is an awful solution to your original problem, but hey if it works for you go with it). Write a class which exhibits this behaviour and attach it to every button which requires it.

                N Offline
                N Offline
                neeraj max
                wrote on last edited by
                #8

                @J4amieC thanks for your 25 customer and single solution example... but this solution is suitable for 2,3 panel only becuase diffrent buttons have diffrent tasks and process time so we cant fix the 500ms for every event. anyways i am looking for more suitable solution..... if you come to know any, let me know.

                J 1 Reply Last reply
                0
                • N neeraj max

                  @J4amieC thanks for your 25 customer and single solution example... but this solution is suitable for 2,3 panel only becuase diffrent buttons have diffrent tasks and process time so we cant fix the 500ms for every event. anyways i am looking for more suitable solution..... if you come to know any, let me know.

                  J Offline
                  J Offline
                  J4amieC
                  wrote on last edited by
                  #9

                  The 500ms had nothing to do with whatever task the button does, it had to do with stopping a quick double click operating a button which appears after the first click. It should not matter what the second button does! Anyway your original question asked about 2 panels, and you got a solution to the question as stated. Ask the right question, and you'll get the right answer.

                  N 1 Reply Last reply
                  0
                  • J J4amieC

                    The 500ms had nothing to do with whatever task the button does, it had to do with stopping a quick double click operating a button which appears after the first click. It should not matter what the second button does! Anyway your original question asked about 2 panels, and you got a solution to the question as stated. Ask the right question, and you'll get the right answer.

                    N Offline
                    N Offline
                    neeraj max
                    wrote on last edited by
                    #10

                    http://www.youtube.com/watch?v=bpojl4XMweo&feature=g-upl above link will explain you my problem very clearly.

                    J 1 Reply Last reply
                    0
                    • N neeraj max

                      http://www.youtube.com/watch?v=bpojl4XMweo&feature=g-upl above link will explain you my problem very clearly.

                      J Offline
                      J Offline
                      J4amieC
                      wrote on last edited by
                      #11

                      No, no it didnt.

                      N 1 Reply Last reply
                      0
                      • J J4amieC

                        No, no it didnt.

                        N Offline
                        N Offline
                        neeraj max
                        wrote on last edited by
                        #12

                        leave it then i will solve it by myself ...

                        1 Reply Last reply
                        0
                        • N neeraj max

                          i have two panel in ma form. panel1 with button1 on it at location let say x:10,y:10 and panel2 with button 2 on it at location x:10,y:10. what actually button1 do:- it hide panel1 and shows panel2 at the same location. but whenever i click on button1 twice after completion its process it fire button2 click event, plz help me ASAP

                          N Offline
                          N Offline
                          neeraj max
                          wrote on last edited by
                          #13

                          by ignoring queued mouse events. i got my answer.

                          @everybody: thank you every one for your suggestions.

                          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