Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use VB.NET Textbox control

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to use the VB.NET Textbox control, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

VB.NET programming language is a development language for face-to-face objects. In this language, there are many control skills worthy of our in-depth study and proficiency, in order to facilitate our development and application. VB.NET Textbox control is also one of the controls often used in applications, which is mainly used to accept user input when the program is running, and can also display the running results to complete the interaction between the user and the program.

TextBox is a general-purpose control that allows users to enter or display text. You cannot use TextBox to display text that you do not want users to change unless the Locked property of TextBox is set to true. The actual text displayed in the TextBox is controlled by the Text property. The Text property can be set in three ways: in the Properties window at design time, through code at run time, or entered by the user at run time.

VB.NET Textbox control 1. Set the text of the text box

Retrieve the current contents of the Text at run time by reading the TextBox property. TextBox displays only single-line text by default, and does not display ScrollBar (scroll bar). If the length of the text exceeds the available space, only part of the text can be displayed. You can change the appearance and behavior of TextBox by setting the MultiLine and ScrollBars properties, which can only be set at program design time.

Note: don't confuse the ScrollBars property with the ScrollBar control, the ScrollBar control does not belong to TextBox, it has its own property set. Setting the MultiLine property to True causes TextBox to accept or display multiple lines of text at run time.

As long as there is no horizontal "ScrollBar", the text in the multiline TextBox will automatically wrap by word. The default value of the ScrollBars property is set to 0 (None). Automatic word wrapping saves the user the trouble of inserting newline characters at the end of the line. When a line of text is longer than it can be displayed, the VB.NET Textbox control automatically folds the text back to the next line. At design time, you cannot enter newline characters in the Properties window. In the process, 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 font size.

VB.NET Textbox control 2. Create a password text box

A password box is a special and common form of a text box that allows placeholders such as asterisks to be displayed at the same time as the user enters the password. Vb.net 2005 provides two text box properties, PasswordChar and MaxLengh, which greatly simplifies the creation of password text boxes. PasswordChar specifies the characters to display in the text box. For example, if you want to display an asterisk in the password box, you can specify the PasswordChar property as "*" in the Properties window, as shown in the figure:

At run time, an asterisk is displayed in the text box no matter what character the user enters in the text box. You can use MaxLength to set the number of characters in the input text box. When the number of characters entered exceeds the MaxLength, the system does not accept the extra characters and beeps.

VB.NET Textbox control 3. Create a read-only text box

You can use the Readonly property to prevent users from editing the contents of the text box. When the Readonly property is set to True, the user can scroll and highlight the text in the text box, but cannot make any changes. When the Readonly property is set to, the runtime can use the copy command in the text box, but not the cut and paste commands. The Readonly attribute affects only the user interaction at run time. At this point, you can still change the Text property to change the contents of the text box at run time through the program.

VB.NET Textbox control 4. Display quotation marks in a string

Quotation marks ("") sometimes appear in a string of text.

For example: She said, "You deserve a treat!" Because the string assigned to a variable or attribute is enclosed in quotation marks (""), an additional pair of quotation marks must be inserted for a pair of quotation marks to be displayed in the string. Visual Basic interprets two pairs of parallel quotation marks as embedded quotation marks.

For example, to display the above string, you should use the following code:

TextBox1.Text= "She said,"

"You deserve a treat!"

ASC Ⅱ characters (34) that are available in quotation marks have the same effect:

TextBox1.Text= "She said,"

& Chr (34) + "You deserve a

Treat! "& Chr (34)

After reading the above, do you have any further understanding of how to use the VB.NET Textbox control? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report