Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In my application: on my main page I have a menu strip containing menu items File and Windows. The File menu contains two menu items File1 and File2. When I click on File1 a new form will open and a menu item f1 is added under windows menu.

Its just like windows menu in Ms Word. Now I am trying to remove menu item f1 when I close the form. What do I do for this? Please help me. Also, I am trying to set a check on the menu item if the form is selected.

See code below:

Form1(MdiContainer)

private void tmFile1_Click(object sender, EventArgs e)
        {
            frmFile1 ft1 = new fromTrail2();
            ft1.MdiParent = this;
            ft1.MS = msFile;
            ToolStripMenuItem tmTrail1 = new ToolStripMenuItem();
            tmTrail1.Name = ft1.Name;
            tmTrail1.Text = "Trail2";
            ft1.STMI = tmTrail1;
            tmForms.DropDownItems.Add(ft1.STMI);
            ft1.Show();
            WinMenu.Add(ft1, tmTrail1);
        }

frmFile1

private MenuStrip MenuSrtp;
        private ToolStripMenuItem stmi;
        public ToolStripMenuItem STMI
        {
            get
         {
                return stmi;
            }
            set
            {
                stmi = value;
            }
        }
        public MenuStrip MS
        {
            set
            {
                MenuSrtp = value;
            }
            get
            {
                return MenuSrtp;
            }
        }

        private void frmTrail1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MS.Items.Remove(stmi);
        }
Posted
Updated 7-Dec-10 0:10am
v2

1 solution

hi
the menustrip contain a property MdiMenuList or MdiWindowList. if you have a window menu named mnuWindow, set this to the MdiMenuList property. all work is doing by the application and no code is required.
 
Share this answer
 
Comments
Yatin Bhagat 8-Dec-10 0:36am    
Thank you....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900