C # use the text attribute of textbox to add the character "\ r \ n" to the line feed"

Source: Internet
Author: User

To make a textbox display multi-line text, you must set its multiline attribute to true. However, if you want to set the text attribute of textbox to multi-line text, A line break consists of two characters: "\ r \ n ".

Textbox1.text = "first \ nsecond \ nthird"; Do not wrap the line when running.

In fact, it is mainly because textbox runs on Windows. The line feed that Windows can display must consist of two characters: "\ 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?

To ensure that the line feed effect can be properly displayed on various platforms, use system. environment. newline.

It can ensure that correct line breaks can be returned on different platforms. \ r \ n in windows and \ n in Linux. Therefore, the above Code should be written:

Atextbox. Text = "first line" + system. environment. newline + "second line" + system. environment. newline + "third line ";

C # use the text attribute of textbox to add the character "\ r \ n" to the line feed"

Related Article

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.