From: http://hi.baidu.com/zhiqingcn/blog/item/416921d1f777313c9b502788.html
To display multiple lines of text in a textbox of a Windows form, you must set its multiline attribute to true.
We all know this, but you may encounter some trouble when setting multiple lines of text for the text attribute in the Code :)
You often think of directly paying a string containing the linefeed "\ n" to the text attribute: atextbox. Text = "first line \ nsecond line \ nthird line ";
However, during actual operation, you find that the line feed is not always displayed, and the result is "first linesecond linethirdline ".
In fact, it is mainly because textbox runs on Windows. A line break that Windows can display must contain two characters: Carriage Return &
Line
Feed, which must be "\ r \ n ". If "\ n" is not displayed as a line break in Windows, it is different from other operating systems such as Linux/Unix. So above
If you replace "\ n" with "\ r \ n", you can.
In fact, the problem is still not well solved, because "\ r \ n" can meet the requirements of windows, but what if it is another platform? To ensure that the line feed effect is positive on various platforms
For more information, see environment. newline. It ensures that correct line breaks are returned on different platforms. In Windows, \ r \ n is returned.
In Linux (Mono), it should be \ n. So the above Code should be written as: atextbox. Text = "first line" +
Environment. newline + "second line" +
Environment. newline + "third line ";
In addition, you can use verbatim string literal (start with @) to enter the line break: atextbox. Text = @ "first line
Second line
Third line ";
This form looks intuitive in the code, but if the code editor runs in Windows, it is still equivalent to entering \ r \ n.