如何在多行文本框中添加文本?

11 c#

我必须将我的文件的详细信息添加到多行文本框中.但是所有细节都在文本框中的一行中添加,而不是在垂直序列中添加.我使用了Environment.NewLine并使用了"\ r \n",但它没有任何帮助.我在Windows窗体表单中勾选了多行文本框,并将其设置为true但无效.

我的代码行是这样的:

m_Txt.Multiline = true;

m_Txt.Text = fileInfo.m_Title + "\r\n" + 
             fileInfo.m_Identifier + Environment.NewLine + 
             fileInfo.m_TotalTime;
Run Code Online (Sandbox Code Playgroud)

Fal*_*eer 16

一个更清洁的答案是:

假设txtStatus是一个文本框:

txtStatus.Multiline = True;
txtStatus.Clear();
txtStatus.Text += "Line 1" + Environment.NewLine;
txtStatus.Text += "Line 2" + Environment.NewLine;
Run Code Online (Sandbox Code Playgroud)

使用内置枚举意味着更清晰的代码.


Jas*_*ver 12

Shift + Enter键

In the Visual Studio resource editor, you can hit "Shift + Enter" 
to create a new line, as doing something like "\r\n" will get escaped 
out.  You will also need to increase the cell height to see both 
lines as it does not auto-size.
Run Code Online (Sandbox Code Playgroud)