TextBox.TextAlign 속성

정의

TextBox 컨트롤의 텍스트 정렬 방법을 가져오거나 설정합니다.

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

속성 값

HorizontalAlignment

컨트롤의 텍스트 정렬 방식을 지정하는 HorizontalAlignment 열거형 값 중 하나입니다. 기본값은 HorizontalAlignment.Left입니다.

예외

열거형의 올바른 값 범위에 속하지 않는 값이 속성에 할당된 경우

예제

다음 코드 예제에서는 암호를 수락하는 데 사용되는 컨트롤을 만듭니다 TextBox . 이 예제에서는 속성을 사용하여 소문자로 입력된 모든 문자를 변경하고 MaxLength 암호 길이를 8자로 제한하는 속성을 사용합니다CharacterCasing. 또한이 예제에서는 합니다 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

설명

이 속성을 사용하여 폼의 텍스트 레이아웃과 TextBox 일치하도록 텍스트 내의 텍스트를 정렬할 수 있습니다. 예를 들어 컨트롤이 모두 폼의 오른쪽에 있는 경우 속성을 설정 TextAlign 하면 HorizontalAlignment.Right텍스트가 기본 왼쪽 맞춤 대신 컨트롤의 오른쪽에 맞춰집니다.

적용 대상

추가 정보