)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to maintain different text for TabHeader in WinForms TabbedMDIManager and Item of ToolStripMenu in MenuStrip?

Platform: WinForms |
Control: TabbedMDIManager |
Published Date: April 13, 2018 |
Last Revised Date: January 28, 2020 |
.NET Framework: 4

TabHeader text

By default, if we add any control as MDI Child that will be added as ToolStripMenuItem and the text of the Form will be displayed as text of the ToolStripMenuItem. But we can modify the text of ToolStripMenuItem while opening the subitems of ToolStripMenu. The following code example illustrate the same,

DropDownOpening event will be triggered while opening the drop down of ToolStripMenu and we must change text of the tool strip menu item here,

C#

private void Form1_Load(object sender, EventArgs e)
{  
  Test2 Form1 = new Test2();
  Form1.Text = "Tab1";
  Form1.Tag = "Location 1";
  Form1.MdiParent = this;
  Form1.Show();
 
  Test3 Form2 = new Test3();
  Form2.Tag = "Location 2";
  Form2.Text = "Tab2";
  Form2.MdiParent = this;
  Form2.Show();
  
  Test4 Form3 = new Test4();
  Form3.Text = "Tab3";
  Form3.Tag = "Location 3";
  Form3.MdiParent = this;
  Form3.Show();
}
 
private void DropDownOpening(object sender, EventArgs e)
{
  int i = 1;
  foreach (System.Windows.Forms.ToolStripItem item in WindowsToolStripMenuItem.DropDownItems)
  {
    ToolStripMenuItem toolStripItem = item as ToolStripMenuItem;
    if(toolStripItem != null && toolStripItem.IsMdiWindowListEntry)
    {
      if(toolStripItem != null)
      {
        string text_Renamed = toolStripItem.Text;
        string removedtext = text_Renamed.Remove(0, 3);
        if(!String.IsNullOrEmpty(removedtext))
        {
          string location_Renamed = LocationText(removedtext).ToString();
          toolStripItem.Text = text_Renamed + " " + location_Renamed;
        }
      }
      i = i + 1;
    }
  }
}
 
private object LocationText(string text)
{
  foreach (Form form in Application.OpenForms)
  {
    if(form.Text == text)
    {
      return form.Tag;
    }
  }
  return text;
}

Screenshots:

The following screenshot illustrates that the Text of the Form will be displayed as Text of the ToolStripMenuItem,

Text of form will be displayed as text of ToolStripMenuItem

The below screenshot is the output of this article,

Text of form will be displayed as text of ToolStripMenuItem

Samples:

VB: http://www.syncfusion.com/downloads/support/directtrac/general/ze/TabbedMDI_VB61062714.zip

C#: http://www.syncfusion.com/downloads/support/directtrac/general/ze/TabbedMDI_CSharp-136252931.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon