Gets or sets how text is aligned in a TextBox control.
[Visual Basic] Public Property TextAlign As HorizontalAlignment [C#] public HorizontalAlignment TextAlign {get; set;} [C++] public: __property HorizontalAlignment get_TextAlign(); public: __property void set_TextAlign(HorizontalAlignment); [JScript] public function get TextAlign() : HorizontalAlignment; public function set TextAlign(HorizontalAlignment);
A HorizontalAlignment that specifies how text is aligned in the control. The default is HorizontalAlignment.Left.
This property is only applicable to multiline TextBox controls.
The following example creates a TextBox control that is used to accept a password. This example uses the CharacterCasing property to change all characters typed to uppercase and the MaxLength property to restrict the password length to eight characters. This example also uses the TextAlign property to center the password in the TextBox control.
[Visual Basic]
Public Sub CreatePasswordTextBox() ' Create an instance of the TextBox control. Dim Text1 as TextBox Set Text1 = New TextBox 'Text1.MaxLength = 8 ' Assign the asterisk to be the password character. Text1.PasswordChar = "*" ' Change all text entered to be lowercase. Text1.CharacterCasing = CharacterCasing.Upper ' Align the text in the center of the TextBox control. Text1.TextAlign = HorizontalAlignment.Center End Sub
TextBox Class | TextBox Members | System.WinForms Namespace | HorizontalAlignment