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

其中一個 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.

例外狀況

不在列舉型別 (Enumeration) 有效值範圍內的值會指派給這個屬性。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 密碼長度限制為八個字元的屬性。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.

適用於

另請參閱