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

 

 

posted @ 2010-01-09 16:40  冯翔  阅读(568)  评论(0编辑  收藏  举报