I have a windows forms app with a textbox control that I want to only accept integer values. In the past I\'ve done this kind of validation by overloading the KeyPress event
I would handle it in the KeyDown event.
void TextBox_KeyDown(object sender, KeyEventArgs e) { char c = Convert.ToChar(e.PlatformKeyCode); if (!char.IsDigit(c)) { e.Handled = true; } }