WinForm中的TextBox控件输入全角数字自动转为半角数字
给TextBox控件加上KeyPress事件,事件代码如下:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if ((int)e.KeyChar >= 65296 && (int)e.KeyChar <= 65305) { e.KeyChar = (char)((int)e.KeyChar - 65248); } }
给TextBox控件加上KeyPress事件,事件代码如下:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if ((int)e.KeyChar >= 65296 && (int)e.KeyChar <= 65305) { e.KeyChar = (char)((int)e.KeyChar - 65248); } }