TextBox.TextAlign Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta la modalità di allineamento del testo in un TextBox controllo .
public:
property System::Windows::Forms::HorizontalAlignment TextAlign { System::Windows::Forms::HorizontalAlignment get(); void set(System::Windows::Forms::HorizontalAlignment value); };
public System.Windows.Forms.HorizontalAlignment TextAlign { get; set; }
member this.TextAlign : System.Windows.Forms.HorizontalAlignment with get, set
Public Property TextAlign As HorizontalAlignment
Valore della proprietà
Uno dei valori di HorizontalAlignment enumerazione che specifica la modalità di allineamento del testo nel controllo . Il valore predefinito è HorizontalAlignment.Left.
Eccezioni
Un valore non compreso nell'intervallo di valori validi per l'enumerazione è stato assegnato alla proprietà .
Esempio
Nell'esempio di codice seguente viene creato un TextBox controllo utilizzato per accettare una password. In questo esempio viene utilizzata la CharacterCasing proprietà per modificare tutti i caratteri digitati in lettere minuscole e la MaxLength proprietà per limitare la lunghezza della password a otto caratteri. In questo esempio viene usata anche la TextAlign proprietà per centrare la password nel TextBox controllo .
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
Commenti
È possibile utilizzare questa proprietà per allineare il testo all'interno di un TextBox oggetto in modo che corrisponda al layout del testo nel modulo. Ad esempio, se i controlli si trovano tutti sul lato destro del form, è possibile impostare la TextAlign proprietà su HorizontalAlignment.Righte il testo verrà allineato al lato destro del controllo anziché all'allineamento sinistro predefinito.