C# - 文本框换行问题 [英] C# - Textbox Newline Problems
问题描述
我有一个文本框,我试图打印到它与下面的代码行:
logfiletextbox。文字= logfiletextbox.Text +\\\
\\\
\\\
\\\
\\\
+ O +复制到+ folderlabel2.Text;
在哪里folderlabel 2显然是一个文本框。我已经把的第一件事是相同的文本框,所以没有文字被删除。过多的新生产线已经证明了我的问题,因为在文本框中没有新线(是的,设置为多行)。该O是一个类型的FileInfo的一个FileInfo数组。
为什么不将这些新行的文本框中显示出来?
< DIV CLASS =h2_lin>解决方案
使用\r\\\
而不是\\\
。窗口的文本框需要CRLF作为行结束符,而不仅仅是LF。
潜在您的可能的使用 Environment.NewLine
而不是 - 但我不知道什么单文本框与\\\
(工作方面做的这是什么 Environment.NewLine
将是对在Linux中)。如果它开始把额外的东西在最后,如果你用\r\\\
,那么,这将打破现有的很多应用程序 - 但如果它的需要的\r\\\
,将打破它使用的应用 Environment.NewLine
。
Environment.NewLine
,就是要为您正在运行的整个平台的默认新行 - 但如果您使用的是小部件工具包,它做一件事情,但文本文件一般做点别的?坦率地说这是一个有点乱。如果有这不同的实现可能会适当地处理一个单独的 TextBox.NewLine
属性这将是很好。
I have a textbox, and I'm trying to print to it with the following line of code:
logfiletextbox.Text = logfiletextbox.Text + "\n\n\n\n\n" + o + " copied to " + folderlabel2.Text;
Where folderlabel 2 is obviously a textbox. The first thing I've put in is the same textbox, so that no text is erased. The excessive new lines have proven my problem, because there are no new lines in the textbox (yes, set to multiline). The "o" is of type FileInfo in a FileInfo array.
Why won't these newlines show up in the text box?
Use "\r\n" instead of "\n". Windows text boxes need CRLF as line terminators, not just LF.
Potentially you could use Environment.NewLine
instead - but I don't know what Mono TextBoxes do in terms of working with "\n" (which is what Environment.NewLine
would be on a Linux box). If it starts putting extra stuff at the end if you use "\r\n" then that will break plenty of existing apps - but if it requires "\r\n" that would break apps which use Environment.NewLine
.
Environment.NewLine
is meant to be the default new line for the whole platform you're running on - but what if you're using a widget toolkit which does one thing, but text files typically do something else? Frankly it's a bit of a mess. It would be nice if there were a separate TextBox.NewLine
property which different implementations could handle appropriately.
这篇关于C# - 文本框换行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!