在下面的示例中,接管了 DockManager.ClosingPanel 事件,来重写当面板被关闭时它的默认行为。 本例中取消了默认的关闭机制,将该面板停靠到窗体的下边缘,并且启用了它的 自动隐藏功能 功能。

C#CopyCode image复制代码
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;
}

Visual BasicCopyCode image复制代码
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