TextBox.TextAlign Egenskap

Definition

Hämtar eller anger hur text justeras i en TextBox kontroll.

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

Egenskapsvärde

Ett av uppräkningsvärdena HorizontalAlignment som anger hur text justeras i kontrollen. Standardvärdet är HorizontalAlignment.Left.

Undantag

Ett värde som inte ligger inom intervallet med giltiga värden för uppräkningen tilldelades egenskapen.

Exempel

I följande kodexempel skapas en TextBox kontroll som används för att acceptera ett lösenord. I det CharacterCasing här exemplet används egenskapen för att ändra alla tecken som skrivs till gemener MaxLength och egenskapen för att begränsa lösenordslängden till åtta tecken. I det här exemplet används TextAlign även egenskapen för att centrera lösenordet i TextBox kontrollen.

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

Kommentarer

Du kan använda den här egenskapen för att justera texten i en TextBox för att matcha layouten för texten i formuläret. Om dina kontroller till exempel alla finns till höger i formuläret kan du ange TextAlign egenskapen till HorizontalAlignment.Right, och texten justeras till höger sida av kontrollen i stället för den vänstra standardjusteringen.

Gäller för

Se även