다음을 통해 공유


RichTextBox.MaxLength 속성

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

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

구문

‘선언
Public Overrides Property MaxLength As Integer
‘사용 방법
Dim instance As RichTextBox
Dim value As Integer

value = instance.MaxLength

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

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

public override function set MaxLength (value : int)

속성 값

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

예외

예외 형식 조건

ArgumentException

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

설명

이 속성이 0으로 설정되어 있으면 컨트롤에 입력할 수 있는 텍스트의 최대 길이는 64KB 문자입니다. 이 속성은 일반적으로 RichTextBox를 사용하여 RTF(서식있는 텍스트 형식) 텍스트를 한 줄 표시하는 데 사용됩니다. 이 속성을 사용하여 우편 번호 및 전화 번호 같은 값에 대해 컨트롤에 입력한 텍스트 길이를 제한하거나 데이터베이스에 데이터를 입력해야 할 때 입력되는 텍스트 길이를 제한할 수 있습니다. 이 때 컨트롤에 입력하는 텍스트를 데이터베이스에 있는 해당 필드의 최대 길이로 제한할 수 있습니다.

참고

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

예제

다음 코드 예제에서는 MaxLength 속성을 사용하여 RichTextBox 컨트롤에 할당되는 텍스트가 MaxLength 속성에 할당된 값보다 큰지 여부를 확인하는 방법을 보여 줍니다. 이 텍스트가 더 크지 않으면 예제에서는 SelectedText 속성을 사용하여 컨트롤에 텍스트를 할당합니다. 이 예제를 실행하려면 richTextBox1이라는 RichTextBox 컨트롤이 폼에 추가되어 있어야 하고, 컨트롤에 붙여넣을 매개 변수에 텍스트를 지정하여 예제의 메서드를 호출해야 합니다. 또한 RichTextBox에 입력할 수 있는 텍스트를 제한하기 위해 MaxLength 속성에 값이 설정되어 있어야 합니다.

Private Sub AddMyText(ByVal textToAdd As String)
    ' Determine if the text to add is larger than the max length property.
    If textToAdd.Length > richTextBox1.MaxLength Then
        ' Alert user text is too large.
        MessageBox.Show("The text is too large to addo to the RichTextBox")
        ' Add the text to be added to the control.
    Else
        richTextBox1.SelectedText = textToAdd
    End If
End Sub
private void AddMyText(string textToAdd)
{
    // Determine if the text to add is larger than the max length property.
    if (textToAdd.Length > richTextBox1.MaxLength)
        // Alert user text is too large.
        MessageBox.Show("The text is too large to addo to the RichTextBox");
    else
        // Add the text to be added to the control.
        richTextBox1.SelectedText = textToAdd;
}
private:
   void AddMyText( String^ textToAdd )
   {
      // Determine if the text to add is larger than the max length property.
      if ( textToAdd->Length > richTextBox1->MaxLength )
         // Alert user text is too large.
         MessageBox::Show( "The text is too large to add to the RichTextBox" ); // Add the text to be added to the control.
      else
         richTextBox1->SelectedText = textToAdd;
   }
private void AddMyText(String textToAdd)
{
    // Determine if the text to add is larger than the max length property.
    if (textToAdd.get_Length() > richTextBox1.get_MaxLength()) {
        // Alert user text is too large.
        MessageBox.Show("The text is too large to addo to the RichTextBox");
    } 
    else {
        // Add the text to be added to the control.
        richTextBox1.set_SelectedText(textToAdd);
    }
} //AddMyText 

플랫폼

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

참고 항목

참조

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