How to create and move docking panels

The creation of a docking panel is very easy and just requires allocating a new instance of the DockControl class and then adding this control to the Controls collection on the parent DockContainer. The DockPosition property on the DockControl instance will determine where the docking panel will appear.

Code Example:

// mc is a DockMainContainerControl

DockControl dc = new DockControl();
mc.Controls.Add(dc);

The code above will create a docking panel and add it to the docking container, placing it in the default location, that is on the left of the docking container the docking panel belongs to. Left here is used loosely because the layout engine will always try to optimize space usage, so if the container only contains one panel this will take all the space of the parent.

As explained above changing the default location can be achieved by setting the DockPosition property and the same rule applies when moving the docking panel to a different position. Docking positions are constructed by defining the general layout displacement of the panel in the layout using the CompactPosition type, then pixel values are calculated by the layout engine.

Code Example:

// this snippet follows the one above

CompactPosition pos = CompactPosition.Self;
dc.DockPosition = pos.ToRight().ToBottom();