我在C#Winforms
richtextboxes
遇到这个问题,无论何时添加新字符串,它都会删除之前显示的字符串并替换它。我想知道C#中是否有一个属性允许我保留前一个字符串并在其下面添加新字符串并继续这样。
答案 0 :(得分:0)
这是任何语言的基本操作,并且被称为 连接或附加文本。 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");