windowsforms-1266-controls-and-libraries-docking-library-managing-dock-panels-in-code-controlling-dock-operations.md
This document describes how to respond to dock operations and cancel or disable them if necessary.
Dock panels provide the DockPanel.Options property which contains a set of options to control dock operations on panels:
| Option | Description |
|---|---|
| DockPanelOptions.AllowDockBottom | Specifies whether the dock panel can be docked to the bottom edge of a form (or user control). |
| DockPanelOptions.AllowDockFill | Specifies whether the dock panel can be docked to another dock panel. |
| DockPanelOptions.AllowDockLeft | Specifies whether the dock panel can be docked to the left edge of a form (or user control). |
| DockPanelOptions.AllowDockRight | Specifies whether the dock panel can be docked to the right edge of a form (or user control). |
| DockPanelOptions.AllowDockTop | Specifies whether the dock panel can be docked to the top edge of a form (or user control). |
| DockPanelOptions.AllowFloating | Specifies whether the dock panel can be floated. |
These options allow you to prevent a panel from being docked at a specific position. However, they don’t provide full control of the docking functionality. For instance, even if a panel’s DockPanelOptions.AllowDockBottom option is set to false , this panel can still be docked to another panel which is docked to the bottom edge of the form.
To resolve this problem, set the panel’s DockPanelOptions.AllowDockFill option to false to prevent it from being docked to other panels, or handle the DockManager.Docking event. This event provides more flexibility to manage dock operations.
Unlike options described above, events provide full control over dock operations. The dock manager provides the following events that fire in response to dock operations being performed by end-users against dock panels, and these can be handled to implement your custom logic.
By default, an end-user can double-click any docked panel’s caption to float it. A subsequent double-click on the floating panel’s caption will restore it to its previous position. This feature can be disabled for all the panels by setting the dock manager’s BaseDockOptions.FloatOnDblClick option to false. To disable this feature for a specific panel, set the panel’s FloatOnDblClick option to false.
The following example demonstrates how to prevent panels from being dragged from containers and from being docked to other panels. This also prevents end-users from destroying the existing container panels.
The DockManager.StartDocking and DockManager.Docking events are handled to restrict the dock operations.
using DevExpress.XtraBars.Docking;
// Prevent a panel from being dragged from a container.
private void dockManager1_StartDocking(object sender, DockPanelCancelEventArgs e) {
DockPanel parentPanel = e.Panel.ParentPanel;
e.Cancel = parentPanel != null;
}
// Prevent a panel from being docked to another panel.
private void dockManager1_Docking(object sender, DockingEventArgs e) {
e.Cancel = e.TargetPanel != null;
}
Imports DevExpress.XtraBars.Docking
' Prevent a panel from being dragged from a container.
Private Sub DockManager1_StartDocking(ByVal sender As Object, ByVal e As DockPanelCancelEventArgs) _
Handles DockManager1.StartDocking
Dim parentPanel As DockPanel = e.Panel.ParentPanel
e.Cancel = Not parentPanel Is Nothing
End Sub
' Prevent a panel from being docked to another panel.
Private Sub DockManager1_Docking(ByVal sender As Object, ByVal e As DockingEventArgs) _
Handles DockManager1.Docking
e.Cancel = Not e.TargetPanel Is Nothing
End Sub
See Also