问题
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