Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Textbox Newline Problems

Tags:

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?

like image 918
muttley91 Avatar asked Jul 08 '10 20:07

muttley91


People also ask

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What do you mean by C?

" " C is a computer programming language. That means that you can use C to create lists of instructions for a computer to follow. C is one of thousands of programming languages currently in use.

What is C language used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...


1 Answers

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.

like image 128
Jon Skeet Avatar answered Sep 20 '22 17:09

Jon Skeet