问题
On my parent form i have a menustrip. I disabled (Enabled=false)
some options by default. However i cannot access the menu from the child where i need to enable these items.
I tried a lot of variations like this in the child form constructor:
string[] visibleItems = new[] { "Export", "Import" }; foreach (ToolStripMenuItem item in MdiParent.MainMenuStrip.Items) //base.MainMenuStrip.Items, MainMenuStrip.Items, base.Menu.MdiListItem.MenuItems won't work either. { if (visibleItems.Contains(item.Name)) item.Enabled = true; }
I get a null pointer error and i cannot seem to find access to the menu i created.
Anyway, if i get it working like this i imagine that i have to disable the items again when the window loses focus or gets closed. So what is a proper method to access the item properties when different forms get opened/closed focused/unfocused?
来源:https://stackoverflow.com/questions/23435074/grey-out-menustrip-items-when-certain-forms-are-open-active-focused