以前是 这样写的
private void textBox11_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar==8)  return;
if (e.KeyChar=='.')  return;
if(e.KeyChar<48)
{
e.Handled=true;
}
else if(e.KeyChar>57)
{
e.Handled=true;
}
}
但是我现在要 某一个textBox 键盘不能用,程序里需要通过扫描枪  把数字 直接打进去,所以要禁用 大小键盘。

解决方案 »

  1.   

    readOnly=true 我还用得着问????
      

  2.   


            private void textBox1_KeyUp(object sender, KeyEventArgs e)
            {
                textBox1.Text = string.Empty;
            }
      

  3.   

    用keycode 不要用 KeyChar 小键盘keycode不一样的  事件用keydown 不要用keypress
      

  4.   

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                e.Handled = true;
            }
      

  5.   

    新手看了这么长时间才知道 ReadOnly是那文本框的属性,正解  支持一楼
      

  6.   

    大哥我跟你说 不行。。 readOnly=true 肯定不行 我试过了。。那样扫描枪也打不进去扫描枪 没写代码 , 就是把条形码 打出来而已
      

  7.   

    Enable=false 应该可以吧,就是不能编辑,但是可以通过程序操作
      

  8.   

            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!(e.KeyChar > 48 && e.KeyChar < 57))
                {               
                    e.Handled = true;
                    return;            }
            }这样可以屏蔽数字以外的所有字符!!!