windowsforms-devexpress-dot-xtrabars-dot-docking-dot-dockmanager-ce4a2d78.md
Occurs when a panel is closing.
Namespace : DevExpress.XtraBars.Docking
Assembly : DevExpress.XtraBars.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Docking")]
public event DockPanelCancelEventHandler ClosingPanel
<DXCategory("Docking")>
Public Event ClosingPanel As DockPanelCancelEventHandler
The ClosingPanel event's data class is DockPanelCancelEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Cancel | Gets or sets whether the operation performed on the processed panel should be cancelled. |
| Panel | Gets the processed dock panel. Inherited from DockPanelEventArgs. |
The ClosingPanel event is fired when a panel is about to be closed. This event occurs for any of the following cases:
This event allows you to prevent a specific panel from being closed or to perform specific actions on the panel (for instance dock a panel to a specific position instead of having it closed). To prevent the panel from being closed the event’s DockPanelCancelEventArgs.Cancel parameter must be set to true. The processed panel is specified by the event’s DockPanelEventArgs.Panel parameter.
The panel will be closed if the Cancel parameter is set to false. Closing a panel doesn’t destroy it instead it simply hides it, the panel’s DockPanel.Visibility property will be set to DockVisibility.Hidden and the panel will be moved to the DockManager.HiddenPanels collection.
After a panel has been closed the DockManager.ClosedPanel event is fired.
It’s also possible to prevent a user from closing panels by hiding their Close buttons via the BaseDockOptions.ShowCloseButton property.
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
See Also