-3

I enter the value textbox. How to stop when a user enters the wrong (entered value is not number) consecutive 3 times or total error is 5. I using C#.

KingOne
  • 1
  • 3

1 Answers1

0

Handle the textbox's TextChanged event. When that event happens, try

Convert.ToInt32(textbox.Text);

If the input isn't number, a NumberFormatException must be thrown. Try to catch that exception. After the exception is caught, you can use

textbox.Text = textbox.Text.Substring(0, textbox.Text.Length - 2);

To delete the last char.

Sweeper
  • 213,210
  • 22
  • 193
  • 313