Articles in this section
Category / Section

How to add a new tab to the WinForms TabbedMDIManager as like Browser?

2 mins read

Add a new tab as tabbed MDI child

WinForms TabbedMDIManager doesn’t have direct support to add new tab to the control as like Browser. But we can achieved this by handling the TabControlAdded event of TabbedMDIManager and Click event of TabControlAdv. Here we have added the “Add New Tab” for adding new tab in TabbedMDIManager while clicking the tab.

C#

// Initialize 
private Syncfusion.Windows.Forms.Tools.TabbedMDIManager tabbedMDIManager1;
TabControlAdv tabControl;
Form form1 = new Form();
Form form2 = new Form();
Form form3 = new Form();
Form form4 = new Form();
Form form5 = new Form(); 
 
// TabbedMDIManager
this.tabbedMDIManager1 = new Syncfusion.Windows.Forms.Tools.TabbedMDIManager();
this.tabbedMDIManager1.AttachedTo = this;
 
// TabbedMDIManager Style
this.tabbedMDIManager1.TabStyle = typeof(Syncfusion.Windows.Forms.Tools.TabRendererWorkbookMode);
this.IsMdiContainer = true;
 
// For Child Tab
form1.Text = "tabpage1";
form2.Text = "tabpage2";
form3.Text = " Add New Tab ";
 
form1.MdiParent = this;
form2.MdiParent = this;
form3.MdiParent = this;
 
form2.Show();
form3.Show();
form1.Show();
 
this.tabbedMDIManager1.TabControlAdded += TabbedMDIManager1_TabControlAdded;
//For Adding New Tab
private void TabbedMDIManager1_TabControlAdded(object sender, 
Syncfusion.Windows.Forms.Tools.TabbedMDITabControlEventArgs args)
{
  tabControl = new TabControlAdv();
  tabControl = args.TabControl;
  //Tab size
  tabControl.ItemSize = new Size(30, 30);
  //Create New Tab, when click the Plus(+) tab
  tabControl.Click += TabControl_Click;
}
 
/// <summary>
/// Event to handle the Add new tab page on click
/// </summary>
private void TabControl_Click(object sender, EventArgs e)
{
  //Add New TabPage
  if(tabControl.SelectedTab.Text == "Add New Tab")
  {
    Form[] forms = this.MdiChildren;
    foreach (Form c in forms)
    {
      if (c.Text == "Add New Tab")
      {
        form4 = new Form();
        form4.Text = "New Tab";
        form4.MdiParent = this;
        form4.Show();
        form3.Close();
        form3 = new Form();
        form3.Text = "Add New Tab";
        form3.MdiParent = this;
        break;
      }
    }
  }
}

VB

' Initialize
Private tabbedMDIManager1 As Syncfusion.Windows.Forms.Tools.TabbedMDIManager
Private tabControl As TabControlAdv
Private form3 As New Form()
Private form4 As New Form()
Private form5 As New Form()
 
' TabbedMDIManager
Me.tabbedMDIManager1 = New Syncfusion.Windows.Forms.Tools. TabbedMDIManager()
Me.tabbedMDIManager1.AttachedTo = Me
 
' TabbedMDIManager Style
Me.tabbedMDIManager1.TabStyle = GetType(Syncfusion.Windows.Forms.Tools.TabRendererWorkbookMode)
Me.IsMdiContainer = True
 
' For Child Tab
Dim form1 As New Form ()
Dim form2 As New Form ()
 
form1.Text = "tabpage1"
form2.Text = "tabpage2"
form3.Text = "Add New Tab"
 
form1.MdiParent = Me
form2.MdiParent = Me
form3.MdiParent = Me
 
form2.Show()
form3.Show()
form1.Show()
 
AddHandler Me.tabbedMDIManager1.TabControlAdded, AddressOf TabbedMDIManager1_TabControlAdded
'For Adding New Tab
Private Sub TabbedMDIManager1_TabControlAdded(ByVal sender As Object, ByVal args As Syncfusion.Windows.Forms.Tools.TabbedMDITabControlEventArgs)
  tabControl = New TabControlAdv()
  tabControl = args.TabControl
  'Tab size
  tabControl.ItemSize = New Size(30, 30)
  'Create New Tab, when click the Plus (+) tab
  AddHandler tabControl.Click, AddressOf TabControl_Click
End Sub
 
''' <summary>
''' Event to handle the Add new tab page on click
''' </summary>
Private Sub TabControl_Click(ByVal sender As Object, ByVal e As EventArgs)
  'Add New TabPage
  If tabControl.SelectedTab.Text = "Add New Tab" Then
    Dim forms() As Form = Me.MdiChildren
    For Each c As Form In forms
      If c.Text = "Add New Tab" Then
        form4 = New Form()
        form4.Text = "New Tab"
        form4.MdiParent = Me
        form4.Show()
        form3.Close()
        form3 = New Form()
        form3.Text = "Add New Tab"
        form3.MdiParent = Me
        Exit For
      End If
    Next c
  End If
End Sub

 

Screenshot

Show the new tab button in TabbedMDIManager control

 

Show the new tab is added in TabbedMDIManager

Sample:

C#:   TabbedMDIManagerNewTab

VB:  TabbedMDIManagerNewTab

Reference link: https://help.syncfusion.com/windowsforms/tabbedmdi/getting-started#add-form-as-tabbed-mdi-child

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied