У меня есть меню со списком «Windows», которое содержит все дочерние элементы mdi благодаря свойству MdiList. Однако есть другие окна, которые не находятся внутри контейнера MDI, которые я хочу перечислить в меню. Я могу легко добавить их в меню, но проблема возникает, когда у одного из детей MDI есть меню. Меню объединены, но меню до Я добавил, что другие окна в список объединены, и это неверно.
Использование DockPanelSuite :
void menuWindow_Popup(object sender, EventArgs e)
{
// Because not all windows are MDI children anymore
// we need to find all the other windows and add them to the menu
// Delete whaterver pre-existed
while (menuWindow.MenuItems.Count > 1)
{
menuWindow.MenuItems.RemoveAt(1);
}
if (dockPanel.FloatWindows.Count > 0)
{
menuWindow.MenuItems.Add(new MenuItem("-"));
// Then add all the floating/docked windows
// Note MDIList takes care of the windows that are in MDI mode
foreach (Form dockContent in dockPanel.FloatWindows)
{
// each event handler closure needs its own form reference (not a shared one)
Form content = dockContent;
var mi = new MenuItem(content.Text,
(EventHandler)delegate(object s, EventArgs ea)
{
if (content.WindowState == FormWindowState.Minimized)
{
content.WindowState = FormWindowState.Normal;
}
content.Show();
content.Focus();
});
mi.Checked = (content == dockPanel.ActiveContent);
menuWindow.MenuItems.Add(mi);
}
}
}