RichTextBox.MaxLength 속성

정의

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

public:
 virtual property int MaxLength { int get(); void set(int value); };
public override int MaxLength { get; set; }
member this.MaxLength : int with get, set
Public Overrides Property MaxLength As Integer

속성 값

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

예외

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

예제

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

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.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 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

설명

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

참고

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

적용 대상

추가 정보