Compartir por


MenuCommand Clase

Definición

Representa un elemento de comando de menú o barra de herramientas de Windows.

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

Ejemplos

En el ejemplo de código siguiente se crea un MenuCommand objeto , se configuran sus propiedades y se agregan a IMenuCommandService.

Cree una instancia de la clase en el Component1 formulario y abra el formulario en un entorno de diseño como Visual Studio. Presione la tecla F1 para invocar .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();
        }
    }

    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 barra de herramientas o menú de Windows. La IMenuCommandService interfaz permite agregar MenuCommand objetos al menú de Visual Studio.

Esta clase proporciona los siguientes miembros:

  • Propiedad de controlador de eventos a la que puede adjuntar un controlador de eventos para el comando.

  • Propiedad CommandID que identifica de forma única el comando.

  • Método Invoke que ejecuta el comando .

  • Método OnCommandChanged que se puede invalidar para controlar el evento que se produce cuando se selecciona un nuevo comando.

  • Marca booleana indica si el comando es Checked, Enabled, Supportedo Visible.

  • Propiedad OleStatus que indica el código de estado del comando OLE para el comando.

  • Invalidación del ToString método .

Constructores

Nombre Description
MenuCommand(EventHandler, CommandID)

Inicializa una nueva instancia de la clase MenuCommand.

Propiedades

Nombre Description
Checked

Obtiene o establece un valor que indica si se comprueba este elemento de menú.

CommandID

Obtiene el CommandID asociado a este comando de menú.

Enabled

Obtiene un valor que indica si este elemento de menú está disponible.

OleStatus

Obtiene el código de estado del comando OLE para este elemento de menú.

Properties

Obtiene las propiedades públicas asociadas a MenuCommand.

Supported

Obtiene o establece un valor que indica si se admite este elemento de menú.

Visible

Obtiene o establece un valor que indica si este elemento de menú está visible.

Métodos

Nombre Description
Equals(Object)

Determina si el objeto especificado es igual al objeto actual.

(Heredado de Object)
GetHashCode()

Actúa como función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
Invoke()

Invoca el comando .

Invoke(Object)

Invoca el comando con el parámetro especificado.

MemberwiseClone()

Crea una copia superficial del Objectactual.

(Heredado de Object)
OnCommandChanged(EventArgs)

Genera el evento CommandChanged.

ToString()

Devuelve una representación de cadena de este comando de menú.

Eventos

Nombre Description
CommandChanged

Se produce cuando cambia el comando de menú.

Se aplica a

Consulte también