To display multiple lines of text in a textbox of a Windows form, you must set its multiline attribute to true. To wrap text in Textbox, you will often think of adding an escape line break "\ n" directly in the place where you want to wrap the text ":
This. textboxdescription. Text = "operation description \ NESC \ t minimized \ nalt + F4 \ t exit \ nshift + F6 \ t set the access address ";
However, during the actual operation, you find that it will never wrap, and the displayed result is
Operation instructions: ESC minimizes Alt + F4 exit SHIFT + F6 set the access address
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 ". Therefore, you can replace "\ n" with "\ r \ n.
This. textboxdescription. Text = "operation description \ r \ NESC \ t minimized \ r \ nalt + F4 \ t exited \ r \ nshift + F6 \ t set the access address ";
The displayed result is
Operation instructions: ESC minimize Alt + F4 exit SHIFT + F6 set access address
You can also use environment. newline, so the aboveCodeCan be written:
This. textboxdescription. TEXT = "operation description" + environment. newline + "ESC \ t minimized" + environment. newline + "Alt + F4 \ t exit" + environment. newline + "Shift + F6 \ t access address setting ";
In addition, you can use verbatim string literal (the string starting with @) to enter the line break:
This. textboxdescription. Text = @ "operation instructions: ESC minimizes Alt + F4 exit SHIFT + F6 set access address"
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:
For details, refer to msdn:
Http://msdn.microsoft.com/en-us/library/8y536wdx (vs.71). aspx