C# Winform textBox 只允许输入数字
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.KeyChar == 8) { e.Handled = false; } }
限制textBox的输入,只能输入数字