TextBox.CharacterCasing 属性

定义

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

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

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

例外

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

示例

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

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 根据应用程序的要求更改字符大小写。 例如,可以将控件中 TextBox 输入的所有字符的大小写更改为大写或小写,以强制实施密码策略。

适用于

另请参阅