private void textBox1_KeyPress(object sender,KeyPressEventArgs e) { //数字0~9所对应的keychar为48~57 e.Handled = true; //输入0-9 if ((e.KeyChar >= 47 && e.KeyChar <= 58)) { e.Handled = false; } }
限制textBox的输入,只能输入数字
2022-03-13 04:44:13
private void textBox1_KeyPress(object sender,KeyPressEventArgs e) { //数字0~9所对应的keychar为48~57 e.Handled = true; //输入0-9 if ((e.KeyChar >= 47 && e.KeyChar <= 58)) { e.Handled = false; } }
限制textBox的输入,只能输入数字