MenuCommand Clase

Definición

Representa un elemento de comando de barra de herramientas o de menú de Windows.Represents a Windows menu or toolbar command item.

public ref class MenuCommand
[System.Runtime.InteropServices.ComVisible(true)]
public class MenuCommand
type MenuCommand = class
Public Class MenuCommand
Herencia
MenuCommand
Derivado
Atributos

Ejemplos

En el ejemplo de código siguiente MenuCommand se crea un objeto, se configuran sus propiedades y se agrega a. IMenuCommandServiceThe following code example creates a MenuCommand object, configures its properties, and adds it to the IMenuCommandService.

Cree una instancia de la Component1 clase en el formulario y abra el formulario en un entorno de diseño como Visual Studio.Create an instance of the Component1 class on your form and open the form in a design environment like Visual Studio. Presione la tecla F1 para invocar MenuCommand.Press the F1 key to invoke the MenuCommand.

#using <system.dll>
#using <system.design.dll>
#using <system.windows.forms.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Security::Permissions;

namespace CppMenuCommand
{
   public ref class CDesigner: public ComponentDesigner
   {
   public:
    [PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")]
      virtual void Initialize( IComponent^ comp ) override
      {
         ComponentDesigner::Initialize( comp );
         IMenuCommandService^ mcs = static_cast<IMenuCommandService^>(comp->Site->GetService( IMenuCommandService::typeid ));
         MenuCommand^ mc = gcnew MenuCommand( gcnew EventHandler( this, &CDesigner::OnF1Help ),StandardCommands::F1Help );
         mc->Enabled = true;
         mc->Visible = true;
         mc->Supported = true;
         mcs->AddCommand( mc );
         System::Windows::Forms::MessageBox::Show( "Initialize() has been invoked." );
      }

   private:
      void OnF1Help( Object^ /*sender*/, EventArgs^ /*e*/ )
      {
         System::Windows::Forms::MessageBox::Show( "F1Help has been invoked." );
      }
   };
}
using System;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace CSMenuCommand
{
    [Designer(typeof(CDesigner))]
    public class Component1 : System.ComponentModel.Component
    {
        private System.ComponentModel.Container components = null;

        public Component1(System.ComponentModel.IContainer container)
        {
            container.Add(this);
            InitializeComponent();
        }

        public Component1()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
        }
    }

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 
    public class CDesigner : System.ComponentModel.Design.ComponentDesigner 
    {
        public override void Initialize(IComponent comp) 
        {
            base.Initialize(comp);

            IMenuCommandService mcs = (IMenuCommandService)comp.Site.
                        GetService(typeof(IMenuCommandService));
            MenuCommand mc = new MenuCommand(new EventHandler(OnF1Help), StandardCommands.F1Help);
            mc.Enabled = true;
            mc.Visible = true;
            mc.Supported = true;
            mcs.AddCommand(mc);
            System.Windows.Forms.MessageBox.Show("Initialize() has been invoked.");
        }

        private void OnF1Help(object sender, EventArgs e) 
        {
            System.Windows.Forms.MessageBox.Show("F1Help has been invoked.");
        }
    }
} 
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

Comentarios

La MenuCommand clase representa información sobre un comando de menú o barra de herramientas de Windows.The MenuCommand class represents information about a Windows menu or toolbar command. La IMenuCommandService interfaz permite agregar MenuCommand objetos al menú de Visual Studio.The IMenuCommandService interface allows you to add MenuCommand objects to the Visual Studio menu.

Esta clase proporciona los siguientes miembros:This class provides the following members:

  • Propiedad de controlador de eventos a la que se puede adjuntar un controlador de eventos para el comando.An event-handler property to which you can attach an event handler for the command.

  • Propiedad CommandID que identifica de forma única el comando.A CommandID property that uniquely identifies the command.

  • Un Invoke método que ejecuta el comando.An Invoke method that executes the command.

  • Un OnCommandChanged método que se puede invalidar para controlar el evento que se produce cuando se selecciona un nuevo comando.An OnCommandChanged method that can be overridden to handle the event that occurs when a new command is selected.

  • Estados de marca booleanos que indican si el Checkedcomando Enabledes Supported,, Visibleo.Boolean flag states that indicate whether the command is Checked, Enabled, Supported, or Visible.

  • OleStatus Propiedad que indica el código de estado del comando OLE para el comando.An OleStatus property that indicates the OLE command status code for the command.

  • Una invalidación para ToString el método.An override for the ToString method.

Constructores

MenuCommand(EventHandler, CommandID)

Inicializa una nueva instancia de la clase MenuCommand.Initializes a new instance of the MenuCommand class.

Propiedades

Checked

Obtiene o establece un valor que indica si el elemento de menú está activado.Gets or sets a value indicating whether this menu item is checked.

CommandID

Obtiene el CommandID asociado al comando de menú.Gets the CommandID associated with this menu command.

Enabled

Obtiene un valor que indica si el elemento de menú está disponible.Gets a value indicating whether this menu item is available.

OleStatus

Obtiene el código de estado del comando OLE para el elemento de menú.Gets the OLE command status code for this menu item.

Properties

Obtiene las propiedades públicas asociadas a la clase MenuCommand.Gets the public properties associated with the MenuCommand.

Supported

Obtiene o establece un valor que indica si se admite el elemento de menú.Gets or sets a value indicating whether this menu item is supported.

Visible

Obtiene o establece un valor que indica si el elemento de menú es visible.Gets or sets a value indicating whether this menu item is visible.

Métodos

Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Heredado de Object)
Invoke()

Invoca el comando.Invokes the command.

Invoke(Object)

Llama al comando con el parámetro determinado.Invokes the command with the given parameter.

MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Heredado de Object)
OnCommandChanged(EventArgs)

Genera el evento CommandChanged.Raises the CommandChanged event.

ToString()

Devuelve una representación en forma de cadena de este comando de menú.Returns a string representation of this menu command.

Eventos

CommandChanged

Se produce cuando cambia el comando de menú.Occurs when the menu command changes.

Seguridad

NamedPermissionSet
para obtener acceso completo a los recursos del sistema.for full access to system resources. Valores de petición LinkDemand: InheritanceDemand,.Demand values: LinkDemand, InheritanceDemand. Estado asociado:Associated state:

Se aplica a

Consulte también: