vb.net textbox control

Source: Internet
Author: User
Tags chr

The

TextBox (text box) control is also one of the controls that are often used in your application, primarily to accept user input when the program is run, or to display the results of a run to complete user interaction with the program. The icon for the TextBox control in the toolbox is shown in the figure:

A

TextBox is a generic control that allows users to enter text or display text. You cannot use a textbox to display text that you do not want the user to change unless you set the TextBox's Locked property to true. The actual text displayed in the TextBox is controlled by the Text property. The Text property can be set in three ways: at design time, at the Properties window, at run time by code, or at run time by user input.
1. Sets the text
of the text box to retrieve the current contents of the TextBox at run time by reading the Text property. The textbox displays only single-line text by default and does not display scrollbar (scroll bars). You can display only a portion of text if the length of the text exceeds the available space. You can change the appearance and behavior of the TextBox by setting the multiline and scrollbars two properties, which can be set only when you design the program. Note: Do not confuse the ScrollBars property with the scrollbar control, the scrollbar control does not belong to the textbox, and it has its own set of properties. Setting the Multiline property to True enables the TextBox to accept or display multiple lines of text at run time. Text in a multiline TextBox is automatically wrapped as long as there is no horizontal "ScrollBar". The default value for the ScrollBars property is set to 0 (None). Automatic word wrapping eliminates the user's trouble inserting line breaks at the end of a line. When a line of text has exceeded the length that it can display, the textbox automatically retraced the text to the next line. At design time, you cannot enter line breaks in the Properties window. During the procedure, you can create a line breakpoint by inserting a carriage return plus a newline character (ANSI characters 13 and 0).
Note: If you set the Multiline property to False, the width of the text box cannot be changed, which is determined by the size of the font.
2. Create a password text box
A password box is a special and commonly used form of a text box that allows placeholders such as asterisks to be displayed while the user enters a password. VB.net 2005 provides both PasswordChar and Maxlengh text box properties, greatly simplifying the creation of password text boxes. PASSWORDCHAR Specifies the characters that are displayed in the text box. For example, if you want to display an asterisk in a password box, you can specify the PasswordChar property as "*" in the Properties window, as shown in the figure:


At run time, an asterisk appears in the text box, regardless of what character the user enters in the text box. You can set the number of characters to enter a text box using MaxLength. After the number of characters entered exceeds maxlength, the system does not accept the extra characters and beeps.
3. Create a read-only text box
You can use the ReadOnly property to prevent users from editing text box contents. When the ReadOnly property is set to True, the user can scroll through and highlight the text in the text box without making any changes. After you set the ReadOnly property to, the runtime can use the Copy command in a text box, but you cannot use the cut and Paste commands. The ReadOnly property affects only user interaction at run time. The Text property can still be changed to change the contents of the text box at run time through the program.
4. Display quotation marks in a string
Quotation marks ("") sometimes appear in the string of text.
For example: She said, "You deserve a treat!" Because the strings assigned to a variable or property are enclosed in quotation marks (""), a pair of additional quotes must be inserted for the pair of quotation marks to be displayed in the string. Visual Basic interprets two pairs of quotation marks in parallel as embedded quotes.
For example, to display the string above, you would use the following code:
textbox1.text= "She said," "You Deserve a treat!" " "

The Ascⅱ character (34) of the available quotes achieves the same effect:
textbox1.text= "She said," &CHR (+) + "You deserve a treat!" &CHR (34)

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.