다음을 통해 공유


TextBox.TextAlign 속성

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

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<LocalizableAttribute(True)> _
Public Property TextAlign As HorizontalAlignment
‘사용 방법
Dim instance As TextBox
Dim value As HorizontalAlignment

value = instance.TextAlign

instance.TextAlign = value
[LocalizableAttribute(true)] 
public HorizontalAlignment TextAlign { get; set; }
[LocalizableAttribute(true)] 
public:
property HorizontalAlignment TextAlign {
    HorizontalAlignment get ();
    void set (HorizontalAlignment value);
}
/** @property */
public HorizontalAlignment get_TextAlign ()

/** @property */
public void set_TextAlign (HorizontalAlignment value)
public function get TextAlign () : HorizontalAlignment

public function set TextAlign (value : HorizontalAlignment)

속성 값

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

예외

예외 형식 조건

InvalidEnumArgumentException

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

설명

이 속성을 사용하면 TextBox 내의 텍스트를 해당 폼의 텍스트 레이아웃에 맞도록 정렬할 수 있습니다. 예를 들어, 컨트롤이 모두 폼의 오른쪽에 있는 경우 TextAlign 속성을 HorizontalAlignment.Right로 설정하면 해당 텍스트가 기본적으로 컨트롤의 왼쪽에 정렬되지 않고 오른쪽에 정렬됩니다.

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE 플랫폼 참고: Pocket PC 기반 응용 프로그램에서 한 줄만 입력할 수 있는 텍스트 상자에는 왼쪽 맞춤만 지원됩니다. 여러 줄을 입력할 수 있는 텍스트 상자에는 왼쪽, 오른쪽 또는 가운데 맞춤이 지원됩니다.

예제

다음 코드 예제에서는 암호를 입력하는 데 사용되는 TextBox 컨트롤을 만듭니다. 이 예제에서는 CharacterCasing 속성을 사용하여 입력된 모든 문자를 대문자로 변경하고 MaxLength 속성을 사용하여 암호 길이를 8자로 제한합니다. 또한 이 예제에서는 TextAlign 속성을 사용하여 암호를 TextBox 컨트롤의 가운데로 정렬합니다.

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
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:
   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.set_MaxLength(8);
    // Assign the asterisk to be the password character.
    textBox1.set_PasswordChar('*');
    // Change all text entered to be lowercase.
    textBox1.set_CharacterCasing(CharacterCasing.Lower);
    // Align the text in the center of the TextBox control.
    textBox1.set_TextAlign(HorizontalAlignment.Center);
} //CreateMyPasswordTextBox
public function CreateMyPasswordTextBox()
 {
    // Create an instance of the TextBox control.
    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;
 }
 

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

TextBox 클래스
TextBox 멤버
System.Windows.Forms 네임스페이스
HorizontalAlignment 열거형