TextBox.CharacterCasing 属性

定义

获取或设置 TextBox 控件是否在字符键入时修改其大小写格式。

C#
public System.Windows.Forms.CharacterCasing CharacterCasing { get; set; }

属性值

CharacterCasing

CharacterCasing 枚举值中的一个值,它指定 TextBox 控件是否修改字符的大小写格式。 默认值为 CharacterCasing.Normal

例外

分配给该属性的值不在该枚举的有效值范围内。

示例

下面的代码示例创建一个 TextBox 用于接受密码的控件。 此示例使用 CharacterCasing 该属性将键入的所有字符更改为小写,并将 MaxLength 密码长度限制为 8 个字符的属性。 此示例还使用 TextAlign 属性在控件中 TextBox 居中设置密码。

C#
public void CreateMyPasswordTextBox()
 {
    // Create an instance of the TextBox control.
    TextBox textBox1 = new TextBox();
    // Set the maximum length of text in the control to eight.
    textBox1.MaxLength = 8;
    // Assign the asterisk to be the password character.
    textBox1.PasswordChar = '*';
    // Change all text entered to be lowercase.
    textBox1.CharacterCasing = CharacterCasing.Lower;
    // Align the text in the center of the TextBox control.
    textBox1.TextAlign = HorizontalAlignment.Center;
 }

注解

可以使用此属性 CharacterCasing 根据应用程序的要求更改字符大小写。 例如,可以将控件中 TextBox 输入的所有字符的大小写更改为大写或小写,以强制实施密码策略。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅