DockManager.ClosingPanel Event

Occurs when a panel is closing.

Namespace: DevExpress.XtraBars.Docking

Assembly: DevExpress.XtraBars.v20.1.dll

Declaration

[DXCategory("Docking")]
public event DockPanelCancelEventHandler ClosingPanel
<DXCategory("Docking")>
Public Event ClosingPanel As DockPanelCancelEventHandler

Event Data

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.

Remarks

The ClosingPanel event is fired when a panel is about to be closed. This event occurs for any of the following cases:

  • an end-user has pressed a panel's Close button;
  • the DockPanel.Close method is called.

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.

Examples

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;
}
See Also