Summary of common methods of C # textbox

Source: Internet
Author: User

When we use C # textbox for development operations, we often encounter the use of C # textbox, then C # textbox Use There are some common skills? such as C # TextBox wrapping processing, in fact, is a number of common operations, then here to introduce you a few of our common needs and solutions.

First, on the C # TextBox selection of the judgment:

    1. int  selectlength= this . Textbox1.selectionlength;//Gets the selected character length   
    2.  
    3. if   ( selectlength ==  this . TextBox1.Text.Length)  {//determines whether to select all   
    4. messagebox.show ( ";  
    5.  

Ii. about C # textbox wrapping, setting cursor position, scrolling with text

C # TextBox Line wrapping

    1. Textboxcontrol.text + = Environment.NewLine;

How do I wrap text when I write in a multi-line textbox? Because of the Windows system, the carriage return takes two characters. So the method is to use \ r \ n tags, such as

    1. label="Calculation " ": ... sum\r\n ";
    2. Textbox.appendtext (Label);

Another way to do this is to use the Environment.NewLine method, which is compatible with Windows and Linux systems.

C # textbox Sets the cursor position to the end of the text

    1. Textboxcontrol.selectionstart = Textboxcontrol.textlength;

C # textbox scrolls with text

    1. Textboxcontrol.scrolltocaret ();

How do I scroll through a multi-line textbox to automatically scroll to the last line after I add text? The method is to use the Scrolltocaret method to automatically scroll to the position of the caret, such as:

    1. Textbox.appendtext (Label);
    2. Textbox.scrolltocaret ();

The contents of the common operations of C # TextBox are introduced here, which hopefully helps you understand and learn about the use of C # textbox.

Summary of common methods of C # textbox

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.