TextBox.TextAlign Eigenschap

Definitie

Hiermee haalt u op of stelt u in hoe tekst wordt uitgelijnd in een TextBox besturingselement.

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

Waarde van eigenschap

Een van de HorizontalAlignment opsommingswaarden die aangeeft hoe tekst in het besturingselement wordt uitgelijnd. De standaardwaarde is HorizontalAlignment.Left.

Uitzonderingen

Een waarde die zich niet binnen het bereik van geldige waarden voor de opsomming bevindt, is toegewezen aan de eigenschap.

Voorbeelden

In het volgende codevoorbeeld wordt een TextBox besturingselement gemaakt dat wordt gebruikt om een wachtwoord te accepteren. In dit voorbeeld wordt de CharacterCasing eigenschap gebruikt om alle tekens te wijzigen die zijn getypt in kleine letters en de MaxLength eigenschap om de wachtwoordlengte te beperken tot acht tekens. In dit voorbeeld wordt ook de TextAlign eigenschap gebruikt om het wachtwoord in het TextBox besturingselement te centreren.

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

Opmerkingen

U kunt deze eigenschap gebruiken om de tekst in een TextBox uit te lijnen zodat deze overeenkomt met de indeling van de tekst in uw formulier. Als de besturingselementen zich bijvoorbeeld allemaal aan de rechterkant van het formulier bevinden, kunt u de TextAlign eigenschap HorizontalAlignment.Rightinstellen op en wordt de tekst uitgelijnd met de rechterkant van het besturingselement in plaats van de standaard linkse uitlijning.

Van toepassing op

Zie ook