简体   繁体   中英

Grey out menustrip items when certain forms are open/active/focused

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?

I know this is an old question, just in case someone faces the same issue. You can try to change the modifiers of the control to Public, and check it out again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM