TextBoxBase.TextLength 속성

정의

컨트롤의 텍스트 길이를 가져옵니다.

public:
 virtual property int TextLength { int get(); };
[System.ComponentModel.Browsable(false)]
public virtual int TextLength { get; }
[<System.ComponentModel.Browsable(false)>]
member this.TextLength : int
Public Overridable ReadOnly Property TextLength As Integer

속성 값

Int32

컨트롤의 텍스트에 포함된 문자의 수입니다.

특성

예제

다음 코드 예제에서는 메서드와 TextLength 속성을 사용하여 AppendText 텍스트를 서로 TextBox 복사하는 방법을 보여 줍니다. 이 예제에서는 명명된 두 개의 TextBox 컨트롤과 textBox2폼에 추가되었으며 해당 속성에 텍스트가 textBox1 할당되어 있어야 합니다Text. textBox1

void AppendTextBox1Text()
{
   // Determine if text is selected in textBox1.
   if ( textBox1->SelectionLength == 0 )

   // No selection made, return.
   return;

   // Determine if the text being appended to textBox2 exceeds the MaxLength property.
   if ( (textBox1->SelectedText->Length + textBox2->TextLength) > textBox2->MaxLength )
         MessageBox::Show( "The text to paste in is larger than the maximum number of characters allowed" ); // Append the text from textBox1 into textBox2.
   else
         textBox2->AppendText( textBox1->SelectedText );
}
private void AppendTextBox1Text()
{
   // Determine if text is selected in textBox1.
   if(textBox1.SelectionLength == 0)
      // No selection made, return.
      return;
   
   // Determine if the text being appended to textBox2 exceeds the MaxLength property.
   if((textBox1.SelectedText.Length + textBox2.TextLength) > textBox2.MaxLength)
      MessageBox.Show("The text to paste in is larger than the maximum number of characters allowed");
   else
      // Append the text from textBox1 into textBox2.
      textBox2.AppendText(textBox1.SelectedText);
}
Private Sub AppendTextBox1Text()
   ' Determine if text is selected in textBox1.
   If textBox1.SelectionLength = 0 Then
      ' No selection made, return.
      Return
   End If
   ' Determine if the text being appended to textBox2 exceeds the MaxLength property.
   If textBox1.SelectedText.Length + textBox2.TextLength > textBox2.MaxLength Then
      MessageBox.Show("The text to paste in is larger than the maximum number of characters allowed")
      ' Append the text from textBox1 into textBox2.
   Else
      textBox2.AppendText(textBox1.SelectedText)
   End If
End Sub

설명

이 속성을 사용 하 여 총 문자 수에 대 한 지식이 필요한 컨트롤의 텍스트 내에서 텍스트의 특정 문자열을 검색 하는 등의 작업에 대 한 문자열의 문자 수를 확인할 수 있습니다.

적용 대상

추가 정보