c#里给多行的 textBox赋值是怎么写的了

如题所述

// 首先,设置TextBox
//1)显示滚动条(垂直)
textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
//2)允许多行显示
this.textBox1.Multiline = true;
//第一种方法:利用StringBuilder
StringBuilder sb = new StringBuilder();
sb.AppendLine("第一行");
sb.AppendLine("第二行");
sb.AppendLine("第三行");
textBox1.Text = sb.ToString();
// 第二种方法:直接附加
textBox1.AppendText("第四行" + Environment.NewLine);
textBox1.AppendText("第五行" + Environment.NewLine);

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-05-02

多行赋值和单行赋值是一样的,都是

textBox.Text="文本";

要换行,则需要换行符"\n"

如代码

textBox.Text="abc\nefg\nhijk";

结果显示

abc

efg

hijk

本回答被提问者和网友采纳