在textBox中控制不能输入中文,
只能输入字母或数字,在C#中如何实现啊?
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
int i1 = 0;
int i2 = 0;
int i3 = 0;
//先获得字符的二进制码
byte[] bytes = System.Text.Encoding.Default.GetBytes(new char[] { e.KeyChar});
i1=(short)bytes[0];
if (bytes.Length != 1)
{
i2 = (short)(bytes[1]);
i3 = 1;
}
else
{
i2 = 65536;
i3 = -1;
}
int charsc = i1 * 256+i2-65536;
if ((charsc <= 0 || charsc >= 160) && (i3 == 1))//输入汉字成立的条件
{
e.Handled = true;
}
}