C # how to wrap multiple textbox lines in winform

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.