If you want to be sure, that the user can just enter a numeric value in a textbox, there is a wise way to check this as following;
private void TextBoxNumericOnly_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8)
{
if ((!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), @"\d+")))
e.Handled = true;
}
}
In the “KeyPress” of textbox the entry is validated with the help of Regular Expression. (e.KeyChar != 8 ensures that backspace is not checked, so that the user can delete his entry with backspace.)