Ezi*_*nze 57
您只需将CharacterChasing属性更改为Upper.
textBox1.CharacterCasing = CharacterCasing.Upper
Run Code Online (Sandbox Code Playgroud)
为什么重新发明轮子,只需将textBox的'CharacterCasing'属性设置为'Upper'.您不需要编写任何代码.

如果是蒙版文本框,您可以使用">"(在掩码属性中)使后续字符为大写.例如,对于长度为8的输入字母数字字符串(AZ,0-9),请使用掩码'> AAAAAAAA'.要限制为仅字母(AZ),请使用'> LLLLLLLL'.

您需要将结果分配ToUpper回文本框:
txtBox.Text = txtBox.Text.ToUpper();
Run Code Online (Sandbox Code Playgroud)
或者,将CharacterCasing文本框的属性设置为Upper:
txtBox.CharacterCasing = CharacterCasing.Upper;
Run Code Online (Sandbox Code Playgroud)