Partager via


Visual Basic Concepts

Adding Methods to Controls

You implement methods of your ActiveX control by adding Public Sub and Function procedures to the code module of the UserControl that forms the basis of your control class.

By default, the only methods your control will have are the extender methods provided by the container, such as the Move method. You can decide what additional methods your control needs, and add code to implement them.

Standard Methods

If your control is not invisible at run time, you should provide a Refresh method. This method should simply call UserControl.Refresh. For user-drawn controls, this will raise the Paint event; for controls built using constituent controls, it will force a refresh of the constituent controls.

It's also a good idea to implement methods commonly found on controls that provide functionality similar to yours. In addition, you may wish to selectively implement methods of the UserControl object, or of its constituent controls.

Using the ActiveX Control Interface Wizard

The ActiveX Control Interface Wizard can assist you in determining what methods to provide, and in delegating to the appropriate constituent controls.

After you have placed all the constituent controls you're going to use on your UserControl, start the wizard and select your control. The wizard will examine your constituent controls, and produce a list of all the properties, methods, and events that appear in all their interfaces, plus those in the UserControl object's interface. You can select from this list those properties, methods, and events you want in your control's interface.

The wizard will produce default mappings of your control's methods to methods of the UserControl object or of constituent controls. In subsequent steps, you can modify these mappings.

When you have finished with determining your control's interface, and delegating to existing methods, the wizard will generate Sub and Function procedures to implement the properties, including delegation code for all your mappings. This greatly reduces the amount of work required to generate a full-featured control.