如何将MDI子实例添加为菜单项-2 [英] How to add mdi child instance as a menuitem -2

查看:88
本文介绍了如何将MDI子实例添加为菜单项-2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中:在我的主页上,我有一个菜单条,其中包含菜单项File和Windows. 文件"菜单包含两个菜单项File1和File2.当我单击File1时,将打开一个新表单,并在Windows菜单下添加了一个菜单项f1.

就像Word女士中的Windows菜单一样.现在,我试图在关闭窗体时删除菜单项f1.我该怎么办?请帮我.另外,如果选择了表单,我会尝试在菜单项上进行检查.

参见下面的代码:

Form1(MdiContainer)

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


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);
        }

推荐答案

hi
菜单条包含属性MdiMenuList或MdiWindowList.如果您有一个名为mnuWindow的窗口菜单,请将其设置为MdiMenuList属性.所有工作都由应用程序完成,不需要任何代码.
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.


这篇关于如何将MDI子实例添加为菜单项-2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆