devxlogo

April 30, 2018

How to Restrict Input Text to Characters in a Text Box

Use the KeyPress event to check for the keys pressed. See below for an example: private void textFirstName_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( !( char.IsLetter(e.KeyChar) ) ) { e.Handled