防止MDI窗口出现在“窗口"菜单列表中

防止MDI窗口出现在“窗口

问题描述:

我有一个.NET MDI应用程序,该应用程序使用 MDI窗口列表自动将子MDI表单填充到窗口"菜单中.

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

是否可以防止某些MDI子窗体不包括在此自动菜单列表中?

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

要求:
-此子表格必须是MDI子表格.
-此表单始终位于MDI表单堆栈的底部.

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

您应该处理菜单项的DropDownOpening事件,然后从列表中删除不需要的项.像这样:

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