在多行文本框中逐行显示文本

Showing line by line text on multiple line textbox

大家好,当我将数据从访问数据库检索到我的文本框多行文本框时,数据显示一行一行我希望任何一行都在它的行中,例如我的访问字段中有 5 行,但在我的文本框在同一行显示所有数据,请问我该怎么做?

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\db\it.accdb");

con.Open();

OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from data where [ID] like(" + textBox9.Text + ")";
cmd.Connection = con;

var reader = cmd.ExecuteReader();
while (reader.Read())
{
    textBox1.Text = reader["Name"].ToString();
    textBox20.Text = reader["Description"].ToString();

    // ----------------------------------------------
    // These doesn't work with me :
    // ----------------------------------------------
    //textBox2.Text = Environment.NewLine;
    //textBox28.Text = textBox28.Text + Environment.NewLine;
    //textBox2.Text = textBox28.Text + Environment.NewLine;

}

con.Close();

使用字符串 'new line character' "\n" 来创建新行。像这样:

textBox1.Text = reader["Name"].ToString() + "\n";
textBox20.Text = reader["Description"].ToString() + "\n";

试试这个,

textBox1.Multiline = true;
textBox1.ScrollBars = ScrollBars.Vertical;//Other settings is Horizontal and Both
textBox1.AcceptsReturn = true;
textBox1.WordWrap = true;

textBox20.Multiline = true;
textBox20.ScrollBars = ScrollBars.Vertical;//Other settings is Horizontal and Both
textBox20.AcceptsReturn = true;
textBox20.WordWrap = true;

while (reader.Read())
{
    textBox1.Text += reader["Name"].ToString() + Environment.NewLine;
    textBox20.Text += reader["Description"].ToString() + Environment.NewLine;
}