windowsforms-5427-controls-and-libraries-docking-library-examples-how-to-override-the-default-behavior-of-a-panel-when-it-is-closed.md
In the following example the DockManager.ClosingPanel event is handled to override the default behavior of the panel when it is closed. The panel being closed will be docked to the bottom edge of the form and its auto-hide functionality will be enabled.
using DevExpress.XtraBars.Docking;
// ...
// Checks if a panel is auto-hidden to the form's bottom edge.
bool IsPanelAutoHiddenBottom(DockPanel panel) {
AutoHideContainer bottomContainer =
panel.DockManager.AutoHideContainers[DockingStyle.Bottom];
if(bottomContainer == null) return false;
return bottomContainer.Contains(panel);
}
private void dockManager1_ClosingPanel(object sender, DockPanelCancelEventArgs e) {
// Cancel the default closing mechanism.
e.Cancel = true;
if(IsPanelAutoHiddenBottom(e.Panel)) return;
// Disable the auto-hide functionality if the panel is auto-hidden.
if(e.Panel.Visibility == DockVisibility.AutoHide)
e.Panel.Visibility = DockVisibility.Visible;
// Dock the panel to the bottom edge of the form and enable its auto-hide functionality.
e.Panel.DockTo(DockingStyle.Bottom);
e.Panel.Visibility = DockVisibility.AutoHide;
}
Imports DevExpress.XtraBars.Docking
' ...
' Checks if a panel is auto-hidden to the form's bottom edge.
Private Function IsPanelAutoHiddenBottom(ByVal panel As DockPanel) As Boolean
' Checks if a panel is auto-hidden to the form's bottom edge.
Dim bottomContainer As AutoHideContainer = _
panel.DockManager.AutoHideContainers(DockingStyle.Bottom)
If bottomContainer Is Nothing Then Return False
Return bottomContainer.Contains(panel)
End Function
Private Sub DockManager1_ClosingPanel(ByVal sender As Object, _
ByVal e As DevExpress.XtraBars.Docking.DockPanelCancelEventArgs) _
Handles DockManager1.ClosingPanel
' Cancel the default closing mechanism.
e.Cancel = True
If IsPanelAutoHiddenBottom(e.Panel) Then Return
' Disable the auto-hide functionality if the panel is auto-hidden.
If e.Panel.Visibility = DockVisibility.AutoHide Then
e.Panel.Visibility = DockVisibility.Visible
End If
' Dock the panel to the bottom edge of the form and enable its auto-hide functionality.
e.Panel.DockTo(DockingStyle.Bottom)
e.Panel.Visibility = DockVisibility.AutoHide
End Sub