MenuCommand Class
Assembly: System (in system.dll)
The MenuCommand class represents information about a Windows menu or toolbar command. The IMenuCommandService interface allows you to add MenuCommand objects to the Visual Studio .NET menu.
This class provides the following members:
-
An event-handler property to which you can attach an event handler for the command.
-
A CommandID property that uniquely identifies the command.
-
An Invoke method that executes the command.
-
An OnCommandChanged method that can be overridden to handle the event that occurs when a new command is selected.
-
Boolean flag states that indicate whether the command is Checked, Enabled, Supported, or Visible.
-
An OleStatus property that indicates the OLE command status code for the command.
-
An override for the ToString method.
The following code example creates a MenuCommand object, configures its properties, and adds it to the IMenuCommandService.
Create an instance of the Component1 class on your form and open the form in a design environment like Visual Studio. Press the F1 key to invoke the MenuCommand.
Imports System Imports System.ComponentModel Imports System.ComponentModel.Design Namespace VbMenuCommand <Designer(GetType(CDesigner))> _ Public Class Component1 Inherits System.ComponentModel.Component Private components As System.ComponentModel.Container = Nothing Public Sub New(ByVal container As System.ComponentModel.IContainer) container.Add(Me) InitializeComponent() End Sub Public Sub New() InitializeComponent() End Sub Private Sub InitializeComponent() End Sub End Class <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Public Class CDesigner Inherits System.ComponentModel.Design.ComponentDesigner Public Overrides Sub Initialize(ByVal comp As IComponent) MyBase.Initialize(comp) Dim mcs As IMenuCommandService = CType(comp.Site.GetService(GetType(IMenuCommandService)), IMenuCommandService) Dim mc As New MenuCommand(New EventHandler(AddressOf OnF1Help), StandardCommands.F1Help) mc.Enabled = True mc.Visible = True mc.Supported = True mcs.AddCommand(mc) System.Windows.Forms.MessageBox.Show("Initialize() has been invoked.") End Sub Private Sub OnF1Help(ByVal sender As Object, ByVal e As EventArgs) System.Windows.Forms.MessageBox.Show("F1Help has been invoked.") End Sub End Class End Namespace
- NamedPermissionSet for full access to system resources. Demand values: LinkDemand, InheritanceDemand. Associated state: FullTrust
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.