添加新文本时保留之前的行

Keep lines before while adding new text

我在使用 C# Winforms richtextboxes 时遇到过这个问题,无论何时添加新字符串,它都会删除之前显示的字符串并替换它。我想知道 C# 中是否有 属性 允许我保留前一个字符串并在其下方添加新字符串并继续这样做。

这是任何语言的基本操作,称为 连接或附加文本。 c#中有很多方法可以做到这一点。

 richTextBox1.Text = "Iam Line 1. ";

 //If you want to append on the same line then
 richTextBox1.Text = richTextBox1.Text + "Iam also Line 1.";

 //Or if you want to append on to the next line
 richTextBox1.Text = richTextBox1.Text + Environment.NewLine + "Iam Line 2.";

 //Also you can go to the next line simply putting \r (Carriage Return) or \n (New Line) Or \r\n
 richTextBox1.Text = richTextBox1.Text + "\n" + "Iam Line 3";
 richTextBox1.Text = richTextBox1.Text + "\r" + "Iam Line 4";
 richTextBox1.Text = richTextBox1.Text + "\r\n" + "Iam Line 5";

 //You can also append using other methods like
 richTextBox1.Text += "\nIam Line 6";
 richTextBox1.Text = string.Concat(richTextBox1.Text, "\nIam Line 7");
 richTextBox1.Text = richTextBox1.Text.Insert(richTextBox1.Text.Length, "\nIam Line 8");