When using Bar control as dockable window with multiple dock tabs, the Bar control creates internal TabStrip control to represents the tabs. The internal tab strip control is returned when Bar.DockTabControl property is referenced.

The Bar control however, depending on it state, might recreate the internal TabStrip control on demand. The Bar.DockTabControl property might also return null if there is no need to display the tab. It is also possible, if dockable tab tear-off is enabled, that end-user might tear-off the tab and create complete new bar thus any event handlers you attached to the Bar.DockTabControl will not be called since new instance of the Bar is created.

To access the internal TabStrip control and attach event handlers to it or change it’s properties below are the steps that must be followed to successfully create such implementation:

  • Handle Bar.ControlAdded event and check ControlEventArgs.Control property in the event handler to see whether TabStrip control is added. If yes, attach event handlers and set custom properties on the control.
  • If you need to apply any styling changes to the control handle Bar.TabStripStyleChanged event which is fired after the internal default styling is set on the TabStrip control
  • If your users can Tear off dockable tabs, handle DotNetBarManager.BarTearOff event and in it attach ControlAdded event handler and apply any tab settings if tab is already created i.e. Bar.DockTabControl <> null

C#:

private void Form1_Load(object sender, EventArgs e)
{
    bar1.ControlAdded += new ControlEventHandler(DockBarControlAdded);
    bar1.TabStripStyleChanged += new EventHandler(DockBarTabStripStyleChanged);
    dotNetBarManager1.BarTearOff += new EventHandler(DockBarBarTearOff);
}
 
private void DockBarControlAdded(object sender, ControlEventArgs e)
{
    if (e.Control is TabStrip)
        OnDockBarTabStripChanged(bar1.DockTabControl);
}
 
private void DockBarBarTearOff(object sender, EventArgs e)
{
    OnDockBarTabStripChanged(bar1.DockTabControl);
}
 
private void DockBarTabStripStyleChanged(object sender, EventArgs e)
{
    OnDockBarTabStripChanged(bar1.DockTabControl);
}
 
private void OnDockBarTabStripChanged(TabStrip newDockTabControl)
{
 
}

VB:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    AddHandler bar1.ControlAdded, AddressOf DockBarControlAdded
    AddHandler bar1.TabStripStyleChanged, AddressOf DockBarTabStripStyleChanged
    AddHandler dotNetBarManager1.BarTearOff, AddressOf DockBarBarTearOff
End Sub
 
Private Sub DockBarControlAdded(ByVal sender As Object, ByVal e As ControlEventArgs)
    If TypeOf e.Control Is TabStrip Then
        OnDockBarTabStripChanged(bar1.DockTabControl)
    End If
End Sub
 
Private Sub DockBarBarTearOff(ByVal sender As Object, ByVal e As EventArgs)
    OnDockBarTabStripChanged(bar1.DockTabControl)
End Sub
 
Private Sub DockBarTabStripStyleChanged(ByVal sender As Object, ByVal e As EventArgs)
    OnDockBarTabStripChanged(bar1.DockTabControl)
End Sub
 
Private Sub OnDockBarTabStripChanged(ByVal newDockTabControl As TabStrip)
 
End Sub

Related posts:

  1. How to Make DotNetBar for WinForms Floating Docking Windows Translucent
  2. How to show custom Tooltip for Schedule Appointments
  3. How to attach Click event handler to Clear or Today buttons in Month Calendar displayed by DateTimeInput control
  4. How to scroll SideBar using MouseWheel
  5. How to to change top-most behavior of floating bars