Skip to main content

Docking Panels to Sites at Runtime

  • 2 minutes to read

This topic provides examples of docking panels to sites and making them float.

You can perform docking operations via code using the DockTo, MakeFloating and UnDock methods of panels and containers. The UnDock method clears a control’s parent and it is recommended that you undock controls before docking them elsewhere. Otherwise, a sequence of actions may result in different layouts depending on the initial layout. The MakeFloating and DockTo methods are used to perform the docking operations.

Consider a simple example of using the DockTo method. (The sample assumes that there are three existing dock panels, named dxDockPanel1, dxDockPanel2 and dxDockPanel3 by default).

dxDockPanel1.DockTo(dxDockSite1, dtLeft, 0);
dxDockPanel2.DockTo(dxDockSite1, dtBottom, 0);
dxDockPanel3.DockTo(dxDockSite1, dtRight, 0);

The resulting panel layout is shown in the image below.

Note

you may need to modify the layout of the dock panels slightly. For instance, you may need the bottom panel (dxDockPanel2) to occupy the entire form’s width. To do this, you have two alternatives. The first is to dock the bottom panel last. In this case, the other panels will be moved to the neighboring layout site. The second approach is to dock the right panel to the bottom panel’s neighboring layout site instead of the dock site. The code below shows the second method. Note that the first two code lines are unchanged.

dxDockPanel1.DockTo(dxDockSite1, dtLeft, 0);
dxDockPanel2.DockTo(dxDockSite1, dtBottom, 0);
dxDockPanel3.DockTo(dxDockPanel2.LayoutDockSite, dtRight, 0);

The resulting dock panel layout is shown in the image below.

The main conclusion at this point is that you need to be aware of the current dock panel layout on a dock site before trying to modify it. Thus, the best way is to undock all the panels before customizing the layout. A further approach is to store the desired layouts and load them when needed. This can be done using the docking manager’s SaveLayoutToIniFile, SaveLayoutToRegistry, SaveLayoutToStream, LoadLayoutFromIniFile, LoadLayoutFromRegistry, LoadLayoutFromStream methods.

The sample code below shows how to make all panels float. (Note: virtually the same code can be used to undock all the panels, by calling the UnDock method instead of MakeFloating.)

var I: Integer;
begin
  with dxDockingController do
  begin
    for I := 0 to DockControlCount - 1 do
    begin
      if DockControls[I] is TdxDockPanel then
        DockControls[I].MakeFloating;
    end;
  end;
end;
See Also