开发者

C# - Textbox Newline Problems

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 开发者_JAVA技巧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.


I believe TextBoxes want an Environment.NewLine (which should be "\r\n")

Note that it must be the carriage return (\r) followed by the new line (\n). If you reverse the order, it won't work.


A TextBox control expects a Carriage Return before your Line Feeds (0x0D 0x0A). Use "\r\n" or System.Environment.Newline.


in stead of using \n we can use

Environment.NewLine

i hope it will help


This is how i created append and new line for display txtitems.Text = txtitems.Text + Environment.NewLine + dr[0].ToString() +" "+dr[1].ToString();


Anyone that is using VB.net, be on the lookout for vbCr

Here is an example:

return "My name is" & vbCr & "John" & vbCr & "Doe"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜