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:
- int selectlength= this . Textbox1.selectionlength;//Gets the selected character length
-  
- if ( selectlength == this . TextBox1.Text.Length) {//determines whether to select all
- messagebox.show ( ";
-  
-
Ii. about C # textbox wrapping, setting cursor position, scrolling with text
C # TextBox Line wrapping
- 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
- label="Calculation " ": ... sum\r\n ";
- 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
- Textboxcontrol.selectionstart = Textboxcontrol.textlength;
C # textbox scrolls with text
- 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:
- Textbox.appendtext (Label);
- 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