1 private void XXXXX_KeyPress(object sender, KeyPressEventArgs e) 2 { 3 //只能输入数字,回车和退格键 4 if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != 13) 5 { 6 e.Handled = true; 7 } 8 }