9. Creating a User Defined ActiveX
Control
So far we have been using the ActiveX Controls which come along with the
Professional Edition of VB-6. We have said
that the greatest power if VB-6 is its capacity to create user defined ActiveX
controls which can be used for building complex applications. We have also pointed out that one can
visualize a scenario, when every complex application will be encapsuled in a
single ActiveX control. In this lesson
we will see how one can go about building one’s own ActiveX
control.
Building a
Picture ActiveX Control:
The Picture
ActiveX Control is intended to print pictures in a Picture box selecting bmp or ico or gif files by
searching the directories.
1. Open
the VB-IDE.
2.
Click
‘New Project’ from the file menu to open the New Project Dialog Box as shown in
the figure 1. Doubleclick on the
ActiveX Control icon. You will get a user control form named as usercontrol1. Open the property window of the form and
change its name property as .rform1 and then change the name property of the
project as
rproj. Drag a picture box,
dir , drive and file controls from the Toolbox, size them and position them as
shown in the figure 2.Open the code window and enter the codes as shown in the
figure 2a.

Figure 1

Figure 2
Private
Sub File1_DblClick()
Picture1.Picture
= LoadPicture(File1.Path & "\" & File1.filename)
End
Sub
Private
Sub Dir1_Change()
File1.Path
= Dir1.Path
End
Sub
Private
Sub Drive1_Change()
Dir1.Path
= Drive1.Drive
End
Sub
Figure 2a
3. Save
the form and the project one by one with the same names you have given
before. The control form is stored as
rform1.ctl and the project is stored as
rproj.vbp. Click ‘Make rproj.ocx’ from the file menu. Save the ocx file as
rproj. Now you have created an ActiveX control by
name rproj.rform This ActiveX control
cannot be used directly. It has to be
placed in a container before we make use of the ActiveX control.
   |