You could always run the
TryParse
on the
keyDown
event so as to validate as the data gets entered. It saves the user an additional UI interaction.
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
int i;
string s = string.Empty;
s += (char)e.KeyValue;
if (!(int.TryParse(s, out i)))
{
e.SuppressKeyPress = true;
textBox2.Text = "An int, that key press would not create";
}
else
{
textBox2.Text = "On the path to a great int, you are";
}
}