TextBox.CharacterCasing 属性

定义

获取或设置 TextBox 控件是否在字符键入时修改其大小写格式。Gets or sets whether the TextBox control modifies the case of characters as they are typed.

public:
 property System::Windows::Forms::CharacterCasing CharacterCasing { System::Windows::Forms::CharacterCasing get(); void set(System::Windows::Forms::CharacterCasing value); };
public System.Windows.Forms.CharacterCasing CharacterCasing { get; set; }
member this.CharacterCasing : System.Windows.Forms.CharacterCasing with get, set
Public Property CharacterCasing As CharacterCasing

属性值

CharacterCasing 枚举值中的一个值,它指定 TextBox 控件是否修改字符的大小写格式。One of the CharacterCasing enumeration values that specifies whether the TextBox control modifies the case of characters. 默认值为 CharacterCasing.NormalThe default is CharacterCasing.Normal.

异常

分配给该属性的值不在该枚举的有效值范围内。A value that is not within the range of valid values for the enumeration was assigned to the property.

示例

下面的代码示例创建一个用于接受密码的 TextBox 控件。The following code example creates a TextBox control that is used to accept a password. 此示例使用 CharacterCasing 属性将键入的所有字符更改为小写,并使用 MaxLength 属性将密码长度限制为8个字符。This example uses the CharacterCasing property to change all characters typed to lowercase, and the MaxLength property to restrict the password length to eight characters. 此示例还使用 TextAlign 属性使密码在 TextBox 控件中居中。This example also uses the TextAlign property to center the password in the TextBox control.

public:
   void CreateMyPasswordTextBox()
   {
      // Create an instance of the TextBox control.
      TextBox^ textBox1 = gcnew 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;
   }
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;
 }
 
Public Sub CreateMyPasswordTextBox()
    ' Create an instance of the TextBox control.
    Dim textBox1 As 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 = "*"c
    ' 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
End Sub

注解

可以使用 CharacterCasing 属性更改应用程序所需的字符大小写。You can use the CharacterCasing property to change the case of characters as required by your application. 例如,可以将在用于密码输入的 TextBox 控件中输入的所有字符的大小写更改为大写或小写来强制执行密码策略。For example, you could change the case of all characters entered in a TextBox control used for password entry to uppercase or lowercase to enforce a policy for passwords.

适用于

另请参阅