C# TextBox控件之大小写自动转换

VS开发C#程序时TextBox的属性中有个Charactercasing属性:默认为normal,把它改为Upper,这样无论你输入的是大写还是小写,在文本框中显示出的都是大写,如果改为Lower的话就是小写.

还可以使用如下方法实现:

1 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
2 {
3     if((int)e.KeyChar>=97 && (int)e.KeyChar<=122) 
4     {
5         e.KeyChar = (char)((int)e.KeyChar - 32);
6     }
7 }

 

posted on 2014-11-21 15:54  teolvp  阅读(2095)  评论(0编辑  收藏  举报

导航