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

Why should VB.NET develop controls?

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is to share with you about why VB.NET is developing controls. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Why do you want VB.NET to develop controls?

To limit the text type of the Windows forms TextBox control, you can add the control's KeyPress event handler to the form code to intercept each keystroke from the user and check whether the character corresponding to that key can enter the TextBox:

Private Sub TextBox1_KeyPress (ByVal sender As Object, _ ByVal e

As System.Windows.Forms.KeyPressEventArgs) _ Handles TextBox1.KeyPress

If Not Char.IsDigit (e.KeyChar) Then

E.Handled = True

Else

E.Handled = False

End If

End Sub

Note that simply by capturing keystrokes, there is no guarantee that the text entered into TextBox is all numeric, because sometimes users do not type characters directly into TextBox, but paste characters to TextBox; through the clipboard, not to mention that the initial value of TextBox text may contain illegal characters. Some other events, such as TextChanged, may be able to catch more illegal input, but I prefer to use Validating or Leave events, which do a word compliance check on TextBox after the user leaves the input control. This does give up the immediate response to user input, but allows the user to first enter a text string of "minor foul" through the clipboard, such as pasting "3425234323422342" in an input box that forbids spaces. Then correct the "foul" character in the input box manually.

It's not too difficult to manually add event handler code to a control, but do you feel so relaxed when faced with more complex programming tasks, such as checking that mailing addresses or car VIN# (vehicle identification number) words conform to the law? At this point, you will want to use the same event handler for multiple forms or even multiple projects, or provide it for sharing with other members of the development team. However, extracting code snippets from a form, along with installation guides and control naming conventions, is the beginning of a nightmare. Fortunately, there is no other way, as long as you release it with a custom control, you will not encounter this nightmare, because the user interface and related code are in separate components, and the release of components is much easier. Code snippets released through components are also easier to upgrade: you just need to release a new version of the component, and you no longer have to publish new code snippets through various channels for programmers to manually overwrite the original code!

Thank you for reading! This is the end of this article on "Why should VB.NET develop controls". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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