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 复制到另一个文本框。本示例要求将两个名为 textBox1textBox2TextBox 控件添加到窗体,而且 textBox1 已将文本分配给它的 Text 属性。

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