Search code examples
c#.netcompact-frameworkwindows-ce

Button Click Event doesn't fire when clicking same button twice in a row


So, a weird one... I have a very simple form with 10 buttons on it. Each as a number on it 0-9. They all have the same Click Event Handler which is shown below.

If I click, say, 4 different buttons in a row it feels fluid and works as expected.
However, if I click the same button(number) twice in a row there is a NOTICEABLE delay on the second click. I can't for the life of me figure out why....

void uxNumberClicked(object sender, EventArgs e)
{
  int num = Convert.ToInt32(((GradientButton)sender).Text);

  if (this.uxPIN.Text.Length < 4)
    uxPIN.Text += num;    
  else
    SystemSounds.Beep.Play();
}

Solution

  • As per our comments, Mouse_Down would look something like this:

    private void uxNumber_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.LeftButton == MouseButtonState.Pressed)
        {
                int num = Convert.ToInt32(((GradientButton)sender).Text);
    
            if (this.uxPIN.Text.Length < 4)
                uxPIN.Text += num;    
            else
            SystemSounds.Beep.Play();
        }
    
    }