C# 如何在多行文本框中添加文本?
我必须将文件的详细信息添加到多行文本框中。但所有细节都是在文本框中的一行中添加的,而不是以垂直顺序添加的。我使用了Environment.NewLine,还使用了“\r\n”,但它没有任何帮助。我在Windows窗体窗体中勾选了多行文本框,并将其设置为true,但没有效果 我的代码行如下:C# 如何在多行文本框中添加文本?,c#,C#,我必须将文件的详细信息添加到多行文本框中。但所有细节都是在文本框中的一行中添加的,而不是以垂直顺序添加的。我使用了Environment.NewLine,还使用了“\r\n”,但它没有任何帮助。我在Windows窗体窗体中勾选了多行文本框,并将其设置为true,但没有效果 我的代码行如下: m_Txt.Multiline = true; m_Txt.Text = fileInfo.m_Title + "\r\n" + fileInfo.m_Identifier +
m_Txt.Multiline = true;
m_Txt.Text = fileInfo.m_Title + "\r\n" +
fileInfo.m_Identifier + Environment.NewLine +
fileInfo.m_TotalTime;
不知道为什么你的代码不能工作,除非发生了其他事情 我刚刚用C#创建了一个WinForms项目,添加了一个文本框,将其设置为多行,并添加了以下代码-非常有用
textBox1.Text = "a\r\nb";
如果是以编程方式进行的,请将新行附加到m_Txt.Lines,这是一个字符串[]
m_Txt.Lines = new string[]{ fileInfo.m_Title, fileInfo.m_Identifier, fileInfo.m_TotalTime};
一个更清晰的答案是:
假设txtStatus是一个文本框:
txtStatus.Multiline = True;
txtStatus.Clear();
txtStatus.Text += "Line 1" + Environment.NewLine;
txtStatus.Text += "Line 2" + Environment.NewLine;
使用内置枚举意味着代码更干净。我刚刚编写了这段代码,似乎工作正常
public void setComments(String comments)
{
String[] aux;
if(comments.Contains('\n')) //Multiple lines comments
{
aux = comments.Split('\n');
for (int i = 0; i < aux.Length; i++)
this.textBoxComments.Text += aux[i] + Environment.NewLine;
}
else //One line comments
this.textBoxComments.Text = comments;
}
public void setComments(字符串注释)
{
字符串[]aux;
if(comments.Contains('\n'))//多行注释
{
aux=comments.Split('\n');
对于(int i=0;i
这真的回答了问题吗?这不是关于设计时的问题,而不是问题中的运行时的问题吗?
public void setComments(String comments)
{
String[] aux;
if(comments.Contains('\n')) //Multiple lines comments
{
aux = comments.Split('\n');
for (int i = 0; i < aux.Length; i++)
this.textBoxComments.Text += aux[i] + Environment.NewLine;
}
else //One line comments
this.textBoxComments.Text = comments;
}