Partager via


Visual Basic Concepts

Interacting with the Container

As explained in "Control Creation Terminology," earlier in this chapter, instances of your control never exist by themselves. They are always placed on container objects, such as Visual Basic forms.

Container objects supply additional properties, methods, and events that appear to the user to be part of your control. This is discussed in the related topic, "Understanding the Container's Extender Object." You can use the Parent property of the Extender object to access the properties and methods of the container your control has been placed on.

You can also obtain information about the container through the UserControl object's Ambient property. The object returned by this property offers hints for property settings, such as BackColor, that can make your control's appearance consistent with that of its container. The AmbientProperties object is discussed in "Using the AmbientProperties Object to Stay Consistent with the Container."

Note   The AmbientProperties and Extender objects are not available until your control has been sited on the container. Thus they are not available in the UserControl object's Initialize event. When the InitProperties or ReadProperties event occurs, the control instance has been sited.

All Containers are Not Created Equal

A consequence of your control's dependence on container objects is that some features may not be available in all containers. Many ActiveX control features require support from the container a control is placed on, and will be disabled if the container doesn't provide the required support.

The following features are supported by Visual Basic forms, but may not be supported by all containers:

  • Transparent control background, discussed in "Giving Your Control a Transparent Background," later in this chapter.

  • The ControlContainer property, discussed in "Allowing Developers to Put Controls on Your Control," later in this chapter.

  • Alignable controls, discussed in "Making Your Control Align to the Edges of Forms," later in this chapter.

  • Modeless dialog boxes your control may show.