다음을 통해 공유


TextBoxBase.MaxLength 속성

TextBox 컨트롤에 입력하거나 붙여넣을 수 있는 최대 문자 수를 가져오거나 설정합니다.

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

구문

‘선언
<LocalizableAttribute(True)> _
Public Overridable Property MaxLength As Integer
‘사용 방법
Dim instance As TextBoxBase
Dim value As Integer

value = instance.MaxLength

instance.MaxLength = value
[LocalizableAttribute(true)] 
public virtual int MaxLength { get; set; }
[LocalizableAttribute(true)] 
public:
virtual property int MaxLength {
    int get ();
    void set (int value);
}
/** @property */
public int get_MaxLength ()

/** @property */
public void set_MaxLength (int value)
public function get MaxLength () : int

public function set MaxLength (value : int)

속성 값

컨트롤에 입력할 수 있는 문자 수입니다. 기본값은 32767입니다.

예외

예외 형식 조건

ArgumentOutOfRangeException

속성에 할당된 값이 0보다 작은 경우

설명

이 속성을 사용하여 우편 번호 및 전화 번호 같은 값에 대해 컨트롤에 입력한 텍스트 길이를 제한하거나 데이터베이스에 데이터를 입력해야 할 때 입력되는 텍스트 길이를 제한할 수 있습니다. 이 때 컨트롤에 입력하는 텍스트를 데이터베이스에 있는 해당 필드의 최대 길이로 제한할 수 있습니다.

참고

코드에서 Text 속성의 값을 MaxLength 속성으로 지정한 값보다 큰 값으로 설정할 수 있습니다. 이 속성은 런타임에 컨트롤에 입력되는 텍스트에만 영향을 줍니다.

Windows NT 4.0, Windows 2000, Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 플랫폼 참고: 한 줄만 입력할 수 있는 TextBox 컨트롤의 경우 MaxLength 속성이 0으로 설정되면 사용자가 입력할 수 있는 최대 문자 수는 2147483646과 사용 가능한 메모리에 따른 크기 중에서 더 작은 값이 됩니다. 여러 줄을 입력할 수 있는 TextBox 컨트롤의 경우 사용자가 입력할 수 있는 최대 문자 수는 4294967295와 사용 가능한 메모리에 따른 크기 중에서 더 작은 값이 됩니다.

Windows Millennium Edition 플랫폼 참고: 한 줄만 입력할 수 있는 TextBox 컨트롤의 경우 MaxLength 속성이 0으로 설정되면 사용자가 입력할 수 있는 최대 문자 수는 32,766과 사용 가능한 메모리에 따른 크기 중에서 더 작은 값이 됩니다. 여러 줄을 입력할 수 있는 TextBox 컨트롤의 경우 사용자가 입력할 수 있는 최대 문자 수는 65,535와 사용 가능한 메모리에 따른 크기 중에서 더 작은 값이 됩니다.

예제

다음 코드 예제에서는 파생 클래스인 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 uppercase.
    textBox1.CharacterCasing = CharacterCasing.Upper
    ' 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 uppercase.
    textBox1.CharacterCasing = CharacterCasing.Upper;
    // 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 uppercase.
      textBox1->CharacterCasing = CharacterCasing::Upper;
      // 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 uppercase.
    textBox1.set_CharacterCasing(CharacterCasing.Upper);
    // Align the text in the center of the TextBox control.
    textBox1.set_TextAlign(HorizontalAlignment.Center);
} //CreateMyPasswordTextBox

플랫폼

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에서 지원

참고 항목

참조

TextBoxBase 클래스
TextBoxBase 멤버
System.Windows.Forms 네임스페이스