I have some code that checks and makes sure that when the users enters in the field an integer from 1 - 10 has to be input.
Although if the users takes focus of the field, the "bad" data (such as "fdgfdg") is still left in the field. So could some demonstrate how when focus is lost on the field, if the data is not valid, a default value will be entered instead e.g. 5
private void textBox4_TextChanged(object sender, EventArgs e)
{
try
{
int numberEntered = int.Parse(textBox4.Text);
if (numberEntered < 1 || numberEntered > 10)
{
MessageBox.Show("You must enter a number between 1 and 10");
}
}
catch (FormatException)
{
MessageBox.Show("You need to enter an integer");
}
}