winform中TextBox只能输入字母

 1  private void txtTestPerson_KeyPress(object sender, KeyPressEventArgs e)
 2         {
 3          
 4             if ((e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') || e.KeyChar == '\b')
 5             {
 6                 e.Handled = false;
 7             }
 8             else
 9             {
10                 e.Handled = true;
11             }
12         }
winform中TextBox只能输入字母_第1张图片
 
 

 

你可能感兴趣的:(winform中TextBox只能输入字母)