Adds the specified standard menu command to the menu.
Assembly: System (in System.dll)
An attempt to add a menu command with an already existing CommandID will throw an InvalidOperationException. When adding a menu command, be sure to check that it is not already on a menu using the FindCommand method, or use exception handling wisely.
You can attach an event handler to a predefined menu command with the following procedure:
If the menu command to link with an event handler has been added to a menu, or is located with the FindCommand method, consider whether you wish to restore this menu command later, and whether you want to invoke the current event handler from your new event handler. If your code might restore the menu command or chain the invocation of event handlers, be sure to store a reference to the menu command somewhere.
Create a new MenuCommand and specify your event handler in the constructor, along with a CommandID representing the command to add. Each standard menu command is associated with a predefined menu location where it is added to. The supported command IDs are defined in the StandardCommands and MenuCommands enumerations.
If you want to invoke any preexisting event handler for the menu command, call the Invoke method of the menu command you have replaced on the menu from the event handler that handles the invoke event of your menu command.
If you are interested in restoring the event handler of a preexisting menu command that you have replaced, add the stored, preexisting menu command after you remove the replacement menu command you created. You may want to add this behavior to the Dispose method for your type.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.