限制 只能输入数字
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != '\b')
{
if ((e.KeyChar < '0') || (e.KeyChar > '9'))
{
e.Handled = true;
}
}
}
限制 数字 范围
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text == "")
textBox2.Text = 0.ToString();
double number = double.Parse(textBox2.Text);
textBox2.Text = number.ToString();
if (number <= 249 && number >= 1)
{
return;
}
MessageBox.Show("只能输入数字且大于1小于249;默认值1", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox2.Text = 1.ToString();
}