Share via


Visual Basic Concepts

Using a Component's Visual Interface

If a component supports object linking and embedding (OLE), you can link or embed an object into your application without writing any code by using the component's visual interface. You can use a component's visual interface in one of two ways:

  • By adding an OLE container control to your application, then inserting an object into the control.

  • By adding the object's class to the Toolbox, then adding an object of that class to your application just as you would add a control to a form.

Inserting an Object with the OLE Container Control

The OLE container control gives you the most flexibility in using an object's visual interface. With the OLE container control, you can:

  • Create a placeholder in your application for an object. You can create the object that appears within the OLE container control at run time, or you can change an object you have placed in the OLE container control at design time.

  • Create a linked object in your application.

  • Bind the OLE container control to a database.

  • Perform an action if the user moves, sizes, or updates the object in the OLE container control.

  • Create objects from data that was copied onto the Clipboard.

  • Display objects as icons.

An OLE container control can contain only one object at a time. There are several ways to create a linked or embedded object in the OLE container control — the one you choose depends on whether you are creating the linked or embedded object at design time or run time. Once you have an OLE container control drawn on your form, you can insert an object into the container control by:

  • Using the Insert Object or Paste Special dialog box. See "Inserting Objects at Design Time with the OLE Container Control" and "Creating Objects at Run Time with the OLE Container Control."

  • Setting the Class, SourceDoc, and SourceItem properties in the Properties window. See "Creating Objects at Run Time with the OLE Container Control."

  • Calling the CreateEmbed****or CreateLink method. See "Creating Objects at Run Time with the OLE Container Control."

For More Information   For more information on using the OLE container control, see "OLE Container Control" and "Containers for Controls" in "Using Visual Basic's Standard Controls."

Inserting an Object by Adding Its Class to the Toolbox

In the same way that you use the Toolbox to add one of Visual Basic's built-in controls to an application, you can use the Toolbox to add an object. First, add the object's class to the Toolbox, then add the object to a form.

To add an object's class to the Toolbox

  1. From the Project menu, choose Components.

  2. In the Components dialog box, click the Insertable Objects tab.

  3. Select the class you want to add to the Toolbox, then click OK. Visual Basic adds a button of that class to the toolbox.

    For example, to add a Microsoft Excel Worksheet button to the Toolbox, select Microsoft Excel Worksheet.

Once you've added the object's class to the Toolbox, you can draw it on a form to create an object of that class. For example, after you add a Microsoft Excel Worksheet button to the Toolbox, you can draw it on a form to create a worksheet object on the form.