Overloading Windows controls

Source: Internet
Author: User

In vb.net, a user can inherit a new Windows control based on a control that already exists, assuming that a text control is now needed, and when you move to the control with the TAB key, the contents of the entire text are highlight, and in VB 6.0, This can be done by writing a new DLL dynamic library, but the TextBox control is blocked in the toolbox and some useful events for the textbox are lost. In VB 7.0, you can derive a new class by inheriting the TextBox class.
for an example, through the Windows design environment, create a form that has two textbox in the form, passed in the project| The Add User Control menu Adds an object named "Hitextbox.vb" to the project so that the control inherits the properties of the textbox instead of customizing a completely new control, as follows:
public class Htextbox
Inherits Textbox
First compile the entire project, and the newly added Htextbox control will appear at the bottom of the toolbar on the left. Users can create a Htextbox class object in any of the Windows Forms that are created.
in the code for the class, insert the following code to implement the highlight function: When you move to the TextBox with the TAB key, the entire contents of the TextBox become hightlight.

public class Httextbox
   Inherits Textbox public
   Sub New
      mybase.new
   ' Add event event handler
   AddHandler enter,_
      New system.eventhandler (addressof_
                   me.ht_enter) End
      Sub
   '----------------
   ' Enter event handler is inside ' class
   Protected Sub Ht_enter (Byval sender as Object,_
             Byval e as System.EventArgs)
      me.selectionstart=0
      Me.selectionlength=me.text.length End Sub-end
Class

This is all the process, and by adding about 10 lines of code, you make a control that inherits from Windows controls.

Related Article

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.