J'ai un menu avec une liste 'Windows' qui contient tous les enfants mdi grâce à la propriété MdiList. Cependant, il existe d'autres fenêtres qui ne sont pas dans le conteneur MDI que je veux répertorier dans le menu. Je peux facilement les ajouter au menu, mais un problème survient lorsque l'un des enfants MDI a un menu. Les menus sont fusionnés, mais le menu avant J'ai ajouté les autres fenêtres à la liste, et est donc incorrect.Comment ajouter MenuItems lorsque les enfants MDI fusionnent leurs menus
En utilisant 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);
}
}
}