Partilhar via


Visual Basic Concepts

Creating the ControlDemo Project

ActiveX controls can be added to any project type. When a control is compiled as part of an .exe file, however, it cannot be shared with other applications. The ShapeLabel control will be compiled into an .ocx file in a later procedure in this chapter, so it can be shared. Thus the ControlDemo project will be created as an ActiveX control project.

An ActiveX control project can contain as many controls as you like. When you build the project, the resulting .ocx file contains all the controls you’ve added.

Note   This topic is part of a series that walks you through creating a sample ActiveX control. It begins with the topic Creating an ActiveX Control.

To create the ControlDemo project

  1. On the File menu, click New Project to open the New Project dialog box. (This will close your current project or project group; you will be prompted to save any changes you have made.) Double-click the ActiveX Control icon to create a new project.

    Visual Basic automatically adds a UserControl designer to the project. The default name, UserControl1, appears as the caption of the designer.

  2. On the Project menu, click Project1 Properties to open the Project Properties dialog box. Select the General tab, fill out the information shown below, and then click OK.

  3. Double-click UserControl1 in the Project Explorer window to bring the designer to the front.

  4. In the Properties window, double-click the Name property and change the name of the user control to ShapeLabel. The new name appears in the caption of the designer and in the Project Explorer window.

    The name you specify becomes the class name of your control, just as CommandButton is the class name for a command button. "Building ActiveX Controls" provides guidelines for choosing class names for controls.

    Notice that the Properties window looks much as it would for a Visual Basic form. Some properties you’re used to seeing are missing, however, and there are properties not found on ordinary Visual Basic forms. These properties are discussed in "Building ActiveX Controls."

  5. Within the control designer, resize the control using the drag handle at the lower right corner of the control, dragging up and left to make the control smaller.

    This sets the default size of the control. For convenience in later procedures, the ShapeLabel control should be of modest size.

  6. On the File menu, click Save Project to save the project files. Name them as shown in the following table. Visual Basic will provide the indicated extensions automatically.

File Filename Extension
User control ControlDemo_ShapeLabel .ctl
Project ControlDemo .vbp
Binary information in a control — such as bitmaps — will be saved in a binary file with the same name and an extension of .ctx.

For More Information   See "Setting Up a New Control Project and Test Project" and "Debugging Controls," in "Building ActiveX Controls."

Step by Step

This topic is part of a series that walks you through creating a sample ActiveX control.

To See
Go to the next step Adding the TestCtlDemo Project
Start from the beginning Creating an ActiveX Control