none
Disable double click

    Question

  • How do you disable the double click event to prevent a user from double clicking on a button when calling a new form.  I am using VB.net visual basic with windows forms and I am not finding where I can do this.  I did button.enabled = false when button first clicked and then to show the form I used form.showdialog.  Then I did button.enabled = true.  It does work but you see the form pulsate like it is actually loading twice.  At first I used form.show and it would load the form and then it would close it so that part is fixed but I don't like to see it look like it is loading twice.  Thanks!

    Thursday, April 08, 2010 9:27 PM

Answers

  • Consider leaving it alone... it is operating "correctly" per Windows conventions.  Soon the user will learn not to double click it on the button.  But I guess you've already ruled that out.

    You could code it to ignore the click if the last button push happened very recently ago.

            private DateTime m_LastAcceptedClick = DateTime.MinValue;
            
            private void button1_Click(object sender, EventArgs e)
            {
                if (DateTime.UtcNow - m_LastAcceptedClick >= TimeSpan.FromSeconds(0.5))
                {
                    System.Diagnostics.Debug.WriteLine("Click accepted.");
    
                    m_LastAcceptedClick = DateTime.UtcNow;
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Click rejected.");
                }
            }
    • Marked as answer by SamAgain Friday, April 16, 2010 9:54 AM
    Thursday, April 08, 2010 11:16 PM