Create a Visual Basic. NET Control from scratch (iii)
Source: Internet
Author: User
visual| Create | Control Step 2nd: Change the base class
Classes created in the control library are automatically named UserControl1 and, by default, inherit from the UserControl class. If we want to create a composite control, it's very easy to just drag the other controls from the Toolbox onto the design surface.
However, since we are creating our own controls from scratch, we need to make some changes. Change the name of the control class from UserControl1 to TrafficLight. Then, the following line will be used:
Inherits System.Windows.Forms.UserControl
Change to:
Inherits System.Windows.Forms.Control
In this way, the most common control class becomes the base class. Instead of displaying the visual design surface, you will find that it is replaced with the component design surface.
To keep the code consistent, change the code file name from UserControl1.vb to Trafficlight.vb. You can make changes in Solution Explorer (Solution Explorer) by right-clicking the name of the code file and choosing Rename (rename).
You also need to add a few lines of code at the top of the class module. Set Option Strict to on and import the namespaces that contain some of the properties that we will use in the future. Here are two lines to put to the top of the code:
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.