文本框限数字输入

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;
}

 

posted on 2012-06-16 12:01  烟雨飘零  阅读(202)  评论(0编辑  收藏  举报

导航