다음을 통해 공유


TextBoxBase.AppendText 메서드

텍스트 상자의 현재 텍스트에 텍스트를 추가합니다.

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

구문

‘선언
Public Sub AppendText ( _
    text As String _
)
‘사용 방법
Dim instance As TextBoxBase
Dim text As String

instance.AppendText(text)
public void AppendText (
    string text
)
public:
void AppendText (
    String^ text
)
public void AppendText (
    String text
)
public function AppendText (
    text : String
)

매개 변수

  • text
    텍스트 상자의 현재 내용에 추가할 텍스트입니다.

설명

연결 연산자(+)를 사용하여 텍스트를 Text 속성에 연결하는 대신 이 메서드를 사용하여 컨트롤의 기존 텍스트에 텍스트를 추가할 수 있습니다.

예제

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

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
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);
}
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.get_SelectionLength() == 0) {
        // No selection made, return.
        return;
    }
    // Determine if the text being appended to textBox2 exceeds the MaxLength
    // property.
    if (textBox1.get_SelectedText().get_Length()
        + textBox2.get_TextLength() > textBox2.get_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.get_SelectedText());
    }        
} //AppendTextBox1Text

플랫폼

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

참고 항목

참조

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