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

谁说我不能喝 提交于 2019-12-24 23:25:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!