Skip to main content

Performing Docking Operations via Code

  • 3 minutes to read

This topic describes how to perform docking operations via code. For a general overview of docking operations, please refer to Docking Operations.

The table below lists dock controls methods that can be used to perform docking operations against them.

Method Description
DockTo Docks the control to a specified control with the specified docking type and index.
MakeFloating Floats the control. A float site becomes the control’s immediate parent as a result.
UnDock Undocks the control. The control has no parent as a result.

The DockTo method accepts three parameters. These are the target control, docking type and docking index. Thus, you can specify where to dock a control, how it must be docked and its position within the new parent’s children list. For instance, the following code can be used to dock one panel to another in order to form a tab container.

dxDockPanelFolders.DockTo(dxDockPanelShortcuts, dtClient, -1);

The above code implies that the Folders panel is docked to the Shortcuts panel with client alignment. Docking index is set to -1 indicating that the control should be added to end of its new parent’s children collection. As such, the Folders panel will correspond to the last tab of the newly created tab container.

The MakeFloating method can be used to float the control. As a result, the control is undocked from its current parent control and the underlying float form and a float site is created for it. Note that the method has two overloads. One of them enables you to float the control and set the position of the float form. If it’s already floating, the method simply changes the position of the float form. Another is equivalent to a double-click docking operation. Please refer to the doDblClickDocking option for details on such operations. This option is available via the Options property of the docking manager.

The following code makes the Folders panel float at the upper left corner of the owner form’s client area.

var
  APoint: TPoint;
// ...
with dxDockPanelFolders do
begin
  APoint := ParentForm.ClientRect.TopLeft;
  APoint := ParentForm.ClientToScreen(APoint);
  MakeFloating(APoint.X, APoint.Y);
end;

The last method used in docking operations is the UnDock method. This method clears the control’s parent. Thus, the control is undocked from any other control and not visible as a result. However, this is not the same as setting the Visible property of a dock control to False. In the latter case, the control remains docked to its parent.

We recommended that you use the UnDock method when customizing the layout of dock controls via code. The reason is that performing the same docking operations on controls can lead to different docking layouts if they are not undocked. If all controls are undocked before rearranging them, the resulting layout will always be the same. Note that all controls are also undocked before restoring the saved layout by calling the LoadLayoutFromIniFile, LoadLayoutFromStream or LoadLayoutFromRegistry method.

The sample code below shows you how to undock all dock panels in an application.

var
  I: Integer;
// ...
I := 0;
with dxDockingController do
begin
  while I < DockControlCount do
  begin
    if (DockControls[I] is TdxDockPanel) and (DockControls[I].ParentDockControl <> nil) then
    begin
      DockControls[I].UnDock;
      I := 0;
    end
    else Inc(I);
  end;
end;
See Also