Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Building ActiveX Controls With VB

Although the Visual Basic Working Model that comes with this text does not support ActiveX control creation, you can use the retail versions of Visual Basic to build your own ActiveX controls. If you like command buttons but you wish they would support a special event or property that your application needs, you can write your own ActiveX command button control, and then use that control as if Visual Basic came with it. You can add the control to your own application's toolbox (through the Project | Components dialog box) and set its properties from the Properties window.

To build an ActiveX control, start a retail version of Visual Basic and select New | Project and select the ActiveX Control icon. Your Visual Basic environment will now look like Figure 21.2.

21fig02.jpg

Figure 21.2 Building an ActiveX control with Visual Basic.

The initial name that VB gives to the control you build is UserControl1; hence the Name property value and the name in the Project window. Most of the tools, windows, and menu objects are exactly the same for the ActiveX control.

Custom controls are tedious to create. Not only must you know Visual Basic and all its language and inner workings (as you do now), but you also need to understand the way ActiveX controls are built, and you must understand the wizards available with VB 6 that help you build the controls. Although you'll need to get some fairly heavy training before you learn to build ActiveX controls, consider the following points:

Share ThisShare This

Informit Network