//使用TextChanged事件
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
string text = ((TextBox)sender).Text;
if(text.Length>0)
{
string newCc = text.Substring(text.Length-1);
char [] chars = newCc.ToCharArray();

bool iscn = false;
foreach(char ch in chars)
{
short st = (short)ch;
if(st>255)
{
iscn = true;
break;
}
}

if(iscn)
MessageBox.Show("是中文");
else
MessageBox.Show("不是中文");
}
}

解决方案 »

  1.   

    在KeyPress事件中进行判断,注意e
      

  2.   

    在KeyPress事件中进行判断,注意e.KeyCharif(e.KeyChar == 'a')
    {
        e.handle = true;
    }
      

  3.   

    /// <summary>
    /// 限制输入数字,用keydown()。
    /// </summary>
    private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    if((e.KeyValue>96&&e.KeyValue<123)||(e.KeyValue>64&&e.KeyValue<91))
     {
     MessageBox.Show("不允许输入字母,请输入数字!");
     if (textBox1.Text!="")
        textBox1.Text=textBox1.Text.Substring(0,textBox1.Text.Length-1);
     }
    }
      

  4.   

    有必要的话当然可以和KeyDown事件一起.
      

  5.   

    用leave事件
    加一个正则表达式来验证
    “\d”验证数字“\.”验证小数点
    无穷次匹配就是了
    数字的政则表达式应该是这样的          [\d\.]+
    很方便,不需要很长的代码
      

  6.   

    // textBox1中只能输入数字
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        if (!(e.KeyChar >= '0' && e.KeyChar <= '9')) e.Handled = true;
    }
      

  7.   

    KeyPress和KeyDown只能控制输入,要是用户选择粘贴就无法控制