How to: Dock panels to a form
- 3 minutes to read
Example 1
In the following code two floating panels are created and then docked to the form referred to by the dock manager’s DockManager.Form property. To dock a panel to a form the DockPanel.DockTo method is used.
The order in which the panels are docked determines the layout of dock panels within the form. The first panel will occupy the form’s left edge entirely, while the second panel will be docked only within the region not occupied by the first panel.
The result is shown below:
using DevExpress.XtraBars.Docking;
// Create two floating panels.
DockPanel dp1 = DockManager1.AddPanel(DockingStyle.Float);
dp1.Text = "dockPanel3";
DockPanel dp2 = DockManager1.AddPanel(DockingStyle.Float);
dp2.Text = "dockPanel1";
// Dock the first panel to left.
dp1.DockTo(DockingStyle.Left);
// Dock the second panel to bottom.
// This panel will be docked within the form's area that isn't occupied by the first panel.
dp2.DockTo(DockingStyle.Bottom);
Example 2
In the following code two panels are created and docked to the form’s left and bottom edges respectively. Then a new floating panel is created, this is docked to the form’s bottom edge so that it occupies this edge entirely. Panels are docked to the form via the DockPanel.DockTo method.
To dock a panel in a specific position amongst the existing panels, you need to use the DockPanel.DockTo overload which takes the index parameter. If index is set to 0, the panel will completely occupy the corresponding edge of the form.
The result is shown below:
using DevExpress.XtraBars.Docking;
// Create two floating panels.
DockPanel dp1 = dockManager1.AddPanel(DockingStyle.Float);
dp1.Text = "Panel 1";
DockPanel dp2 = dockManager1.AddPanel(DockingStyle.Float);
dp2.Text = "Panel 2";
// Dock the first panel on the left
dp1.DockTo(DockingStyle.Left);
// Dock the second panel to the bottom.
// This panel will be docked within the form's area that isn't occupied by the first panel.
dp2.DockTo(DockingStyle.Bottom);
// Create a floating panel.
DockPanel dp3 = dockManager1.AddPanel(DockingStyle.Float);
dp3.Text = "Panel 3";
// Dock this panel so that it occupies the form's bottom edge entirely.
dp3.DockTo(DockingStyle.Bottom, 0);