private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsDigit(e.KeyChar)) { MessageBox.Show("只能输入数字"); e.Handled = true;//文本框不接受不正确的输入 } } private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { textBox2.ImeMode = ImeMode.Off;//关闭输入法。只能输入字母了 } private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar>='0'&&e.KeyChar <='9') e.Handled=false; else e.Handled=true; }