i have textbox on a windows form and i want to be insert only numbers in this textbox.i use the following c# code for that
private void ChildAge_TextChanged(object sender, EventArgs e)
{
int i;
if (!int.TryParse(ChildAge.Text, out i))
{
MessageBox.Show("Plaese enter a valid Age");
}
}
it is working, but the problem is that , after showing the Message, when i Backspace the content and text box become null, on that situation also this message box shows again.
ChildAge.Textbecomes null? Not the actualChildAge?(!string.IsNullOrWhitespace(ChildAge.Text) && !int.TryParse(ChildAge.Text, out i))OnKeyPressand cancel any presses that don't passchar.IsDigit.