如何在c#中一个接一个地将变量输出到富文本框?

void ClearAllRichtextboxes() { richTextBox3.Clear(); richTextBox5.Clear(); richTextBox6.Clear(); richTextBox9.Clear(); richTextBox10.Clear(); } ClearAllRichtextboxes(); if (comboBox5.Text == "Primer") { richTextBox5.Text = "This is the number of primer tins" + primer.ToString(); richTextBox6.Text = "This is the cost of the primer tins" + primercost.ToString(); } if (comboBox3.Text == "Matt") { richTextBox10.Text = "This is how many 2.5 tins of paint are needed: " + val44.ToString(); richTextBox9.Text = "This is the matt cost" + valmatt.ToString(); } if (comboBox3.Text == "Vinyl ") { richTextBox10.Text = "This is how many 2.5 tins of paint are needed" + val44.ToString(); richTextBox9.Text = "This is the of vinyl cost" + valmatt.ToString(); } if (comboBox3.Text =="Silk") { richTextBox10.Text = "This is how many 2.5 tins of paint are needed" + silkval.ToString(); richTextBox9.Text = "This is the cost: " + valcostsilk.ToString(); } 

目前我正在将文本插入多个文本框中,而我想在一个富文本框中输出变量 – 通过附加字符串。

你可以做一些像字符串格式化的东西来帮助用空格来区分字符串。

就像是

 richTextBox1.Text = String.Format("This is the number of A in B: {0}\r\n This is the number of X in Y: {1}", output1, output2); 

\ r \ n表示一个新行,您可以在msdn上找到有关String.Format()方法的更多信息: https ://msdn.microsoft.com/en-us/library/system.string.format( v = vs 0.110)的.aspx

使用新信息更新richTextBox.Text 。 如果要将新字符串附加到已存在的字符串,请使用“+”。 如果有帮助,您可以将字符串保存为自己的变量。

 richTextBox.Text = "First segment."; richTextBox.Text = richTextBox.Text + " Second segment."; 

有关字符串连接的更多信息: https : //docs.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/how-to-concatenate-multiple-strings