From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from Object)

Used to embed a group of controls in a Window or in another control.

For web apps, see WebContainer.
Activate DropObject MouseMove
CancelClose EnableMenuItems MouseUp
Close GotFocus MouseWheel
ConstructContextualMenu KeyDown Moved
ContentsChanged KeyUp Open
ContextualMenuAction LostFocus Paint
Deactivate MouseDown Resized
DragEnter MouseDrag Resizing
DragExit MouseEnter ScaleFactorChanged
DragOver MouseExit
AllowAutoDeactivate Enabled MouseX fa-lock-32.png
AllowFocus Focus MouseY fa-lock-32.png
AllowFocusRing Handle fa-lock-32.png Parent
AllowTabs HasBackgroundColor ScaleFactor fa-lock-32.png
Backdrop Height Tooltip
BackgroundColor Left Top
Bounds LockBottom Transparent
Changed LockLeft TrueWindow fa-lock-32.png
Composited LockRight Visible
ControlCount fa-lock-32.png LockTop Width
DockItem fa-lock-32.png MouseCursor Window
AcceptFileDrop Controls Invalidate
AcceptPictureDrop DrawInto Refresh
AcceptRawDataDrop EmbedWithin RefreshRect
AcceptTextDrop EmbedWithinPanel SetFocus
BitmapForCaching FocusNext UpdateNow
Close FocusPrevious
Control Hide


In the Layout Editor, do not layer other controls onto ContainerControls that have been added to a Window layout. Controls added this way are not part of the ContainerControl and will not display properly. Instead, add your controls directly to the ContainerControl in its layout.
ContainerControls can not be part of a Control Set.

ContainerControl is not a Control (despite its name), nor is it a Window. It is a separate class that is similar to Control and to Window, providing many of the same events, properties, and methods. Like a Window, a ContainerControl can encapsulate related Controls (and other ContainerControls) in a self-contained, reusable class. Like a Control, a ContainerControl can be added to a Window, a TabPanel, a PagePanel, or to another ContainerControl.

You can embed a ContainerControl in a Window or ContainerControl in either the IDE or via code. Multiple levels of embedding are supported.

To add the ContainerControl to a window via code, use either the EmbedWithin or EmbedWithinPanel methods. Use EmbedWithin to embed the ContainerControl in either a window or a control, depending on whether the first parameter is a Window or a control. For the special case of embedding within a PagePanel or a TabPanel, use EmbedWithinPanel instead. It allows you to pass the page number on which the ContainerControl will be embedded. To remove the container, use the Close method.

The following statement embeds a ContainerControl at so that its top left corner is 50 points from the left side of the window and 100 points from the top.

ContainerControl1.EmbedWithin(Self, 50, 100)

When the project is run, the controls in the ContainerControl appear in the default window, Window1. Use the same approach to embed the ContainerControl in a control other than a PagePanel or TabPanel; for the latter types of controls, use EmbedWithinPanel and pass the name of the control and the desired panel number.

ContainerControls have multiple uses, You can:

Organize groups of controls into reusable interface components,
Create custom controls made up of several constituent controls,
Increase encapsulation of complex window layouts,
Create dynamic layouts.

For the most part, ContainerControls act as you would expect. For example, if you put code in the MouseMove event of an embedded ContainerControl, the event will fire when your mouse moves over the embedded ContainerControl's boundaries. There are a few things you need to be aware of:

The Handle property of a ContainerControl and the Handle property of controls of an ContainerControl are Nil until the Open event. All of the other properties can be manipulated before the Open event.

A ContainerControl either has its own keyboard focus and menu handling, or it shares these elements with its containing Window. Which behavior is chosen depends on the state of the AllowFocus flag when the ContainerControl is embedded. When AllowFocus is True, the ContainerControl does not share focus with the containing Window. If a containing window has embedded that which share focus with it, those windows will get a first crack at handling it. If none handle it, the containing window will get a try. This applies to KeyDown and MenuCommands. It also affects how menu commands are enabled.

Some properties are new to ContainerControls and relate to its behavior when embedded; these behave like the corresponding properties of the Canvas control. These include the following: LockLeft, LockTop, LockRight, LockBottom, Enabled, AutoDeactivate, HelpTag, UseFocusRing, AllowFocus, AllowTabs, Parent and Window.

Miscellaneous Issues

Use the Open event for initialization instead of overriding the Constructor to allow all the controls to finish setting themselves up.

The Moved, Resized, and Resizing events fire on embedded windows when the embedded window is moved or resized.

The Show/Hide and the Visible property can be used to set the visibility of embedded windows.

Nesting ContainerControls is allowed. However, you can't embed a ContainerControl such that the containing ContainerControl or a ContainerControl higher in the containing chain is another instance of the same ContainerControl; in other words, you can't recursively nest ContainerControls in other instances of themselves.

Nested ContainerControl coordinates for controls and events are automatically transformed for you. You don't need to worry about them unless you are dealing with global coordinates as you would for the MenuItem's Popup method.

See Also

Window classes