In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use the VB.NET text box, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
In Visual Basic, text box (TextBox) is the most commonly used control, skillful use of text box is the basis for the development of high-quality applications. In the course of application development, the author tries to find out the application skills of text boxes and write them out to share with VB enthusiasts.
VB.NET text box processing 1. Set read-only text box
Sometimes a piece of information is displayed in the window, but you don't want the user to change it. How to make the text read-only? First of all, we can use the read-only attribute of the label box (label) to replace the text box with tags to achieve the read-only attribute, but we can also use Mini Program to achieve the real text box read-only.
Sub Text1_KeyPress
(keyascii As Integer)
Keyascii = 0
End Sub
Alternatively, you can use the sendkey method to make the text box lose focus, such as the following program:
Sub Text1_KeyDown
(KeyCode As Integer
Shift As Integer)
SendKeys "{tab}"
End Sub
Or set the properties of the control directly, as follows:
Set Text1.Enabled=True so that Text1 cannot get focus after setting it
Set Text1.Locked=True so that Text1 can get focus after setting it
VB.NET text box processing 2. Define the input content and format of the text box
The following program allows you to restrict text boxes to entering only numbers:
Private Sub Text1_KeyPress
(KeyAscii As Integer)
If KeyAscii
< Asc(0) Or KeyAscii >Asc (9) Then
KeyAscii = 0
MsgBox "Please enter a number"
End If
End Sub
If you want to limit the input format of the text box, you can use the FORMAT function of VB or the professional version of the masking control (Masked Edit). You can precisely control the input format of the text box by setting the Mask property of the masking control.
Summary of practical experience of VB.NET basic data types
Interpretation of VB.NET Override processing method
Introduction to the Application method of creating Virtual Directory by VB.NET
Solutions to the discrepancy of VB.NET parameter types
Correct understanding of VB.NET function calls
VB.NET text box processing 3. Create shortcut keys for TextBox
VB stipulates that the controls added to the form record their loading order in their Tabindex property, and the program runtime focus jumps between controls in the order specified by the Tabindex property. To simplify the operation, a shortcut key can be created in VB for any control that has a caption attribute, which is achieved by prefixing the letter you want to use as a shortcut key with a & sign in the caption attribute. One problem worth noting, however, is that controls such as text boxes do not have properties such as caption, so you can use labels with text boxes at the same time. To create a shortcut key for lable, the label Tabindex property setting is 1 smaller than the text box, and because label cannot receive clicks, the focus automatically jumps to the text box. This is equivalent to creating a shortcut key for the text box. The specific steps are as follows:
(1) draw the label first, then draw the text box. Or draw all kinds of controls at will, and set the label Tabindex attribute to be smaller than the text box by 1.
(2) use the "&" sign to set the shortcut key in the caption attribute of the tag
This is equivalent to setting a shortcut for the text box, and when you press the shortcut key for the label box, the focus jumps to the text box.
VB.NET text box processing 4. Wrap the text box at design time
For text boxes, you cannot enter line breaks in the design properties window, but you can wrap them with code when the program is executed, even with 13 and 10 of the ASCII characters, such as the following Mini Program, you can put two lines of text into the text box:
Sub form_load ()
NL=chr (13) + chr (10)
Text1.text= "my name
Is "& NL &" liu qiang "
End sub
VB.NET text box processing 5. Create password text box
The password text box can be created by setting properties or by calling the API API of WINDOWS. First, the text box properties Passwordchar and maxlength can be used to set the password box. Where Passwordchar specifies the characters displayed in the text box, if you specify "*", it displays "*" in the text box, and Maxlength determines how many characters can be entered in the text box. After the Maxlength is exceeded, the text box warns and cannot receive any more characters. If you use WINDOWS application function interface, you can use interface functions such as GetWindowLong, SetWindowsLong and SendMessage.
Thank you for reading this article carefully. I hope the article "how to use the VB.NET text box" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.