Search code examples
c#menustrip

Sharing MenuStrip between Forms


I have a question a litle bit connected with this one: How to create navigation inside program Form - noob alert again.

I'm trying to create a navigation inside c# program like a dynamic dropdown menu on website. I'm using diferent C# Forms like each and every one one was a different webpage with content.

Is is posible to share menustrip with navigation between Forms? (simplest web similarity: include('menu.php') - put everything into one file I inlcude on every webpage )

Otherwise it would require to copy menustrip to each new Form (then MenuStrip changes, and then what? Copy them again ? :) )


Solution

  • You can do it via joining tabs with Srip Meni like this:

    //make tabs invisible (so you wont see them changing)
    private void HideAllTabsOnTabControl(TabControl theTabControl)
    {
        theTabControl.Appearance = TabAppearance.FlatButtons;
        theTabControl.ItemSize = new Size(0, 1);
        theTabControl.SizeMode = TabSizeMode.Fixed;
    }
    
    //hide all tabs
    private void hide_all_tabs() {
        Tab_content.TabPages.Remove(tabPage1);
        Tab_content.TabPages.Remove(tabPage2);
        Tab_content.TabPages.Remove(tabPage3);
        Tab_content.TabPages.Remove(tabPage4);
    }
    private void materiałyQCToolStripMenuItem_Click(object sender, EventArgs e)
    {
        hide_all_tabs(); //hide everything
        Tab_content.TabPages.Add(tabPage1); //schow just first tab
    }
    private void analizatoryQCToolStripMenuItem_Click(object sender, EventArgs e)
    {
        hide_all_tabs();
        Tab_content.TabPages.Add(tabPage2);
    }
    private void QCzDzisiajToolStripMenuItem_Click(object sender, EventArgs e)
    {
        hide_all_tabs();
        Tab_content.TabPages.Add(tabPage3);
    }
    private void standlabToolStripMenuItem_Click(object sender, EventArgs e)
    {
        hide_all_tabs();
        Tab_content.TabPages.Add(tabPage4);
    }