devxlogo

How to Restrict Input Text to Characters in a Text Box

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 = true;    } }

devx-admin

Share the Post: