The
UserControl object is the basis for any custom
ActiveX control. It provides the container that holds all the rest of the control's
features. You may initiate your project's
UserControl in
one of two ways:
If you chose to add a UserControl to your project, then the
project is probably not an ActiveX project to begin with. This may be exactly the situation
you desire if you've chosen to implement your ActiveX control as part of another project
(see "ActiveX Controls in Other Projects"). If, however,
you wish to convert your project to an ActiveX control project, all you need to do is change
the Project Type option on the General tab of the Project Property dialog box (see Figure
13.3).

FIGURE 13.1 Beginning your project as an ActiveX Control project.
FIGURE 13.2 Adding a UserControl object to your project
FIGURE 13.3 Adjusting the project type
Programming with a UserControl is a lot like programming
with a form. The UserControl object has its
own Designer Window in the VB design-time environment, just like a form does, and a
UserControl appears as one of your project's elements in the
Project Explorer. It appears under a special node labeled "User Controls." You
place constituent controls on the surface of the User Control from the toolbox, just as you
do when programming with a form.
The UserControl has its own properties,
which we discuss in some of the following sections. You can access these properties at design-time
just like you'd access the design-time properties of a form:
Make sure that you've selected the
UserControl object itself (and not one of its constituent controls), and then go to the
Properties Window by pressing F4 or right-clicking the mouse.
To access a UserControl 's
event procedures, make sure that you've selected the
UserControl itself (and not one of its constituent controls), then double-click
the mouse to view UserControl code.
NOTE - Referring to the UserControl
's Members in Code : When you write code in the
UserControl, you can refer to the UserControl's
own built-in members (properties and methods) by referring to the members alone
without reference to the UserControl object. For
example:
BackColor = vbRed
This is similar to the way that you can program within a Form. Note, however,
that the Me keyword does not work in a UserControl
(you will receive a compile- time error if you use Me).