定义文本框的KeyPress事件
View Code
1 private void txtDateEmployed_KeyPress(object sender, KeyPressEventArgs e) 2 { 3 //获取按键的ASCII值 4 int ascii = (int)e.KeyChar; 5 if (ascii >= 48 && ascii <= 57 ) 6 { 7 //允许输入 8 e.Handled = false; 9 } 10 else 11 { 12 e.Handled = true; 13 } 14 }

浙公网安备 33010602011771号