Prevent MDI window to appear in the Window menu list

烈酒焚心 提交于 2021-01-28 07:23:39

问题


I have a .NET MDI application that uses the MDI Window List to automatically populate child MDI forms into the Window menu.

Is it possible to prevent certain MDI child forms not be included in this automatic menu list?

Requirements:
- This child form has to be an MDI child.
- This forms is always at the bottom of the MDI form stack.


回答1:


You should handle the DropDownOpening event of the menu item, and remove the unwanted item from the list. Something like this:

MenuStrip ms = new MenuStrip();
ToolStripMenuItem windowMenu = new ToolStripMenuItem("Window");
ms.MdiWindowListItem = windowMenu;

windowMenu.DropDownOpening += (sender, e) =>
        {
            if (windowMenu.DropDownItems.Count > 0)
                windowMenu.DropDownItems.RemoveAt(0);
        };

ms.Items.Add(windowMenu);
ms.Dock = DockStyle.Top;            
this.MainMenuStrip = ms;
this.Controls.Add(ms);


来源:https://stackoverflow.com/questions/2425221/prevent-mdi-window-to-appear-in-the-window-menu-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!