Transferred from: http://www.cnblogs.com/gaohades/archive/2006/08/29/489199.htmlto display multi-line text in a textbox of a Windows form, you must set its multiline attribute to true.
Everyone knows this, but when you want Code It may be difficult to set multiple lines of text for the text attribute :)
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. The line feed that Windows can display must consist of two characters: Carriage Return & line feed, that is, "\ r \ n ". If "\ n" is not displayed as a line break in Windows, it is different from other operating systems such as Linux/Unix. Therefore, you can replace "\ n" with "\ r \ n.
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? Use environment. newline to ensure that the line feed effect can be properly displayed on various platforms. It can ensure that correct line breaks can be returned on different platforms. \ r \ n in windows and \ n in Linux (Mono. Therefore, the above Code should be written: Atextbox. Text = " First line " +
Environment. newline + " Second line " +
Environment. newline + " Third Line " ; In addition, you can use verbatim string literal (the string starting 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.
Environment is a static class located under the system namespace.ProgramAccess to the running environment and platform information. It provides many useful static attributes and methods:
Specific can refer to the msdn: http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/cpref/html/frlrfsystemenvironmentmemberstopic. asp