Visual Basic Concepts

Adding Controls to a Project

See Also

The set of controls available in the toolbox can be customized for each project. Any given control must be in the toolbox before you can add it to a form in the project. The basic set of standard controls that always appear in the toolbox is described in "Forms, Controls, and Menus."

Adding ActiveX Controls to a Project

You can add ActiveX controls and insertable objects to your project by adding them to the toolbox.

To add a control to a project's toolbox

  1. From the Project menu, choose Components.

    The Components dialog box is displayed, as shown in Figure 4.3. The items listed in this dialog box include all registered ActiveX controls, insertable objects, and ActiveX designers.

  2. To add a control (.ocx file name extension) or an insertable object to the toolbox, select the check box to the left of the control name.

    To view controls with .ocx file name extensions, select the Controls tab. To view insertable objects, such as a Microsoft Excel Chart, select the Insertable Objects tab.

  3. Choose OK to close the Components dialog box. All of the ActiveX controls that you selected will now appear in the toolbox.

Figure 4.3   The Components dialog box

To add ActiveX controls to the Components dialog box, choose the Browse button, and search other directories for files with a .ocx file name extension. When you add an ActiveX control to the list of available controls, Visual Basic automatically selects the check box.

Note   Each ActiveX control is accompanied by a file with an .oca extension. This file stores cached type library information and other data specific to the control. The .oca files are typically stored in the same directory as the ActiveX controls and are recreated as needed (file sizes and dates may change).

Removing Controls from a Project

To remove a control from a project

  1. From the Project menu, choose Components.

    The Components dialog box is displayed.

  2. Clear the check box next to each control you want to remove.

    The control icons will be removed from the toolbox.

Note   You cannot remove any control from the toolbox if an instance of that control is used on any form in the project.

Using Other Applications' Objects

You can also use objects from other applications, such as those included in the Microsoft Excel object library, either as controls in the toolbox or as programmable objects in your code. To add objects to the toolbox, see "Adding Controls to a Project" earlier in this chapter.

To make another application's objects available in your code, but not as controls, set a reference to that application's object library.

To add a reference to another application's object library

  1. From the Project menu, choose References.

    The References dialog box is displayed, as shown in Figure 4.4.

  2. Select the check box next to each reference you want to add to your project.

    To add references to applications not listed in the References dialog box, choose the Browse button, and then select the application.

  3. Choose OK to add the selected references to your project.

Figure 4.4   The References dialog box

If you are not using any objects in a referenced library, you should clear the check box for that reference to minimize the number of object references Visual Basic must resolve, thus reducing the time it takes your project to compile.

Once you have set references to the object libraries you want, you can find a specific object and its methods and properties in the Object Browser by choosing Object Browser from the View menu. You can use any object listed in the Object Browser in your code.

For More Information   " For information on the Object Browser, see "Finding Out About Objects" in "Programming with Objects."

Using a Resource File

A resource file allows you to collect all of the version-specific text and bitmaps for an application in one place. This can include constant declarations, icons, screen text, and other material that may change between localized versions or between revisions or specific configurations.

To add a file to a project

  1. From the Project menu, select Add File.

    The Add File dialog box is displayed.

  2. Select an existing resource file (.res) and choose Open.

A single project can have only one resource file; if you add a second file with a .res extension, an error occurs.

For More Information   For more information on the contents of a resource file, see "International Issues."