Method below has been included now in BarUtilites library that ships with DotNetBar. You can use it instead of the code below.

Use: BarUtilites.SetDockContainerVisible

________________________________________________________

Method below encapsulates all the logic that you need to hide the DockContainerItem objects on the bar and automatically hide/show the bar when last DockContainerItem object has been hidden/shown.

v2 version below uses SuspendLayout to optimize display.

///
/// Sets the visible property of DockContainerItem and hides the bar if the given item is the last visible item on the bar.
/// It will also automatically display the bar if bar is not visible.
///
///
DockContainerItem to set visibility for.
///
Indicates the visibility of the item
private void SetDockContainerVisible(DevComponents.DotNetBar.DockContaine rItem item, bool visible)
{
   if(item==null || item.Visible==visible)
      return;
 
   int visibleCount=0;
   DevComponents.DotNetBar.Bar containerBar=item.ContainerControl as DevComponents.DotNetBar.Bar;
   if(containerBar==null)
   {
      // If bar has not been assigned yet just set the visible property and exit
      item.Visible=visible;
      return;
   }
 
   DotNetBarManager manager=containerBar.Owner as DotNetBarManager;
   if(manager!=null)
      manager.SuspendLayout=true;
 
   try
   {
      foreach(DevComponents.DotNetBar.BaseItem dockItem in containerBar.Items)
         if(dockItem.Visible) visibleCount++;
 
      if(visible)
      {
         item.Visible=true;
         if(!containerBar.AutoHide && !containerBar.Visible && visibleCount<=1)
         {
             containerBar.Visible=true;
             if(containerBar.Tag.ToString()=="autohide")
                   containerBar.AutoHide=true;
         }
      }
      else
      {
         item.Visible=false;
         if(visibleCount==1)
         {
             // Remember auto-hide setting
             if(containerBar.AutoHide)
             {
                containerBar.AutoHide=false;
                containerBar.Tag="autohide";
             }
             else
                containerBar.Tag="";
 
             containerBar.Visible=false;
         }
      }
   }
   finally
   {
      if(manager!=null)
         manager.SuspendLayout=false;
      else
         containerBar.RecalcLayout();
   }
}

VB Version:

'
' Sets the visible property of DockContainerItem and hides the bar if the given item is the last visible item on the bar.
' It will also automatically display the bar if bar is not visible.
'
'
DockContainerItem to set visibility for.
'
Indicates the visibility of the item
Private Sub SetDockContainerVisible(ByVal item As DevComponents.DotNetBar.DockContainerItem, ByVal visible As Boolean)
 
   If item Is Nothing OrElse item.Visible = visible Then Exit Sub
 
   Dim visibleCount As Integer = 0
   Dim containerBar As DevComponents.DotNetBar.Bar = CType(item.ContainerControl, DevComponents.DotNetBar.Bar)
 
   If containerBar Is Nothing Then
      ' If bar has not been assigned yet just set the visible property and exit
      item.Visible = visible
      Exit Sub
   End If
 
   Dim manager As DotNetBarManager = CType(containerBar.Owner, DotNetBarManager)
   If Not manager Is Nothing Then manager.SuspendLayout = True
 
   Try
      Dim dockItem As DevComponents.DotNetBar.BaseItem
      For Each dockItem In containerBar.Items
         If dockItem.Visible Then visibleCount = visibleCount + 1
      Next
 
      If visible Then
         item.Visible = True
         If Not containerBar.AutoHide And Not containerBar.Visible And visibleCount <= 1 Then
             containerBar.Visible = True
             If containerBar.Tag.ToString() = "autohide" Then containerBar.AutoHide = True
         End If
      Else
         item.Visible = False
         If visibleCount = 1 Then
             ' Remember auto-hide setting
             If (containerBar.AutoHide) Then
                containerBar.AutoHide = False
                containerBar.Tag = "autohide"
             Else
                containerBar.Tag = ""
             End If
             containerBar.Visible = False
         End If
      End If
   Finally
      If Not manager Is Nothing Then
         manager.SuspendLayout = False
      Else
         containerBar.RecalcLayout()
      End If
   End Try
End Sub

Related posts:

  1. How to tear-off DockContainerItem using code
  2. Working with DotNetBar from code.
  3. Global Items
  4. Changing NavigationPane Color Scheme
  5. Dockable Bar.Text property changes do not appear