According to http://msdn.microsoft.com/en-us/library/aa984351%28VS.71%29.aspx
Disabling the first or toplevel menu item in a menu (for example, the "File" menu item in a traditional File menu) disables all the menu items contained within the menu. Likewise, disabling a menu item that has submenu items disables the submenu items.
According to http://msdn.microsoft.com/en-us/library/ms171655.aspx
Disabling the first or top-level menu item in a menu disables all the menu items contained within the menu. Likewise, disabling a menu item that has submenu items disables the submenu items.
However, if I create a new Windows Forms project and add the following code, I can still use the shortcut key to access the Child
menu item that, according to MSDN, should be disabled.
public Form1()
{
InitializeComponent();
// Main menu
MenuStrip mainMenu = new MenuStrip();
this.Controls.Add(mainMenu);
// Top Level menu
ToolStripMenuItem topLevelMenuItem = new ToolStripMenuItem("&Top Level");
mainMenu.Items.Add(topLevelMenuItem);
// Child menu item
ToolStripMenuItem childMenuItem = new ToolStripMenuItem("&Child...", null, (o, e) => MessageBox.Show("Doing something."));
childMenuItem.ShortcutKeys = Keys.Control | Keys.C;
childMenuItem.ShortcutKeyDisplayString = "Ctrl + C";
topLevelMenuItem.DropDownItems.Add(childMenuItem);
// Menu item to toggle the Top Level menu's Enabled property
mainMenu.Items.Add(new ToolStripMenuItem("Toggle Enable for Top Level menu", null, (o, e) =>
{
topLevelMenuItem.Enabled = !topLevelMenuItem.Enabled;
MessageBox.Show("topLevelMenuItem.Enabled = " + topLevelMenuItem.Enabled + Environment.NewLine + "childMenuItem.Enabled = " + childMenuItem.Enabled);
}));
}
I can see that childMenuItem.Enabled
is not changing at all, while topLevelMenuItem.Enabled
does.
Sure, I could use a for loop to disable all menu items under the Top Level
menu, or even disable just the Child
menu item, but according to MSDN I shouldn't have to. What's the deal? Am I missing something, misinterpreting something, or is MSDN just wrong?