Share via


Visual Basic Concepts

Compiling the ControlDemo Component

Once you have created an ActiveX control project containing one or more UserControl objects, you can compile it into an .ocx file and use the controls in other applications. The following procedures demonstrate this.

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.

Compiling the ControlDemo project

  1. If the TestCtlDemo project is still in run mode, click the Close button on Form1 to return to design mode.

  2. In the Project Explorer window, click ControlDemo to select the project.

  3. On the File menu, click Make ControlDemo.ocx to open the Make Project dialog box. Click OK to build the .ocx file.

  4. On the File menu, click Remove Project to remove ControlDemo from the project group, so that Visual Basic will use the compiled binary component (.ocx file) instead of the project.

    Visual Basic displays a warning message, because the TestCtlDemo project contains a reference to ControlDemo. Click Yes to remove ControlDemo anyway.

    When you remove ControlDemo from the project group, Visual Basic looks for ControlDemo.ocx in the Windows Registry. If the .ocx file exists, Visual Basic automatically updates the reference you set in the procedure "Adding the TestCtlDemo Project."

    To switch back to using the project instead of the binary component, you can click Add Project, on the File menu, and add the ControlDemo project back to the project group.

  5. Press F5 to run TestCtlDemo using the .ocx file.

When ControlDemo is running from source code, you cannot access the ShapeLabel control from other applications, or from another copy of Visual Basic. This is because ActiveX control components must run in process. Once you have compiled a .ocx component, you can test it from other applications.

To use ControlDemo.ocx in another copy of Visual Basic

  1. Open a new instance of Visual Basic. In the New Project dialog box, double-click the Standard EXE icon to open an .exe project.

  2. On the Project menu, click Components to open the Components dialog box. On the Controls tab, check ActiveX Control Creation Demo, and then click OK.

    The icon for ShapeLabel appears on the Toolbox. You can now add ShapeLabel controls to the default form, and use the Properties window to set their properties. You can also right-click on an instance of ShapeLabel, and choose Properties from the Context menu to edit the control’s properties with the property page.

  3. Press F5 to run the project.

    You can also compile the project and run the .exe.

For More Information   An .ocx file can contain multiple controls and property pages. "Distributing Controls," in "Building ActiveX Controls," discusses control packaging and distribution.

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 Control Creation Recap
Start from the beginning Creating an ActiveX Control