TextBox.CharacterCasing 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 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 列舉值,指定 TextBox 控制項是否修改字元的大小寫。 預設為 CharacterCasing.Normal
。
例外狀況
不在列舉型別 (Enumeration) 有效值範圍內的值會指派給這個屬性。
範例
下列程式碼範例會 TextBox 建立用來接受密碼的 控制項。 這個範例會 CharacterCasing 使用 屬性,將所有輸入為小寫的字元變更,而 MaxLength 屬性則會將密碼長度限制為八個字元。 這個範例也會使用 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 輸入的所有字元大小寫變更為大寫或小寫,以強制執行密碼的原則。