MenuCommand Osztály

Definíció

Egy Windows menü vagy eszköztár parancselemét jelöli.

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
Öröklődés
MenuCommand
Származtatott
Attribútumok

Példák

Az alábbi példakód létrehoz egy MenuCommand objektumot, konfigurálja annak tulajdonságait, és hozzáadja azt a IMenuCommandService.

Hozzon létre egy példányt a Component1 osztályból az űrlapon, és nyissa meg az űrlapot egy tervezőkörnyezetben, például Visual Studio. Az F1 billentyű lenyomásával hívja meg a 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

Megjegyzések

A MenuCommand osztály egy Windows menü vagy eszköztár parancs információinak felel meg. A IMenuCommandService felületen MenuCommand objektumokat vehet fel a Visual Studio menübe.

Ez az osztály a következő tagokat biztosítja:

  • Eseménykezelő tulajdonság, amelyhez csatolhat egy eseménykezelőt a parancshoz.

  • A CommandID parancsot egyedileg azonosító tulajdonság.

  • A Invoke parancsot végrehajtó metódus.

  • Egy OnCommandChanged olyan metódus, amely felülírható az új parancs kiválasztásakor bekövetkező esemény kezeléséhez.

  • Logikai jelző azt jelzi, hogy a parancs Checked, Enabledvagy SupportedVisible.

  • Egy OleStatus tulajdonság, amely a parancs OLE parancsállapotkódját jelzi.

  • A metódus felülbírálása ToString .

Konstruktorok

Name Description
MenuCommand(EventHandler, CommandID)

Inicializálja a MenuCommand osztály új példányát.

Tulajdonságok

Name Description
Checked

Beolvas vagy beállít egy értéket, amely jelzi, hogy a menüelem be van-e jelölve.

CommandID

Lekéri a CommandID menüparancshoz társított parancsot.

Enabled

Beolvas egy értéket, amely jelzi, hogy ez a menüelem elérhető-e.

OleStatus

Lekéri az OLE parancs állapotkódját ehhez a menüelemhez.

Properties

Lekéri a MenuCommand.

Supported

Lekéri vagy beállít egy értéket, amely jelzi, hogy ez a menüelem támogatott-e.

Visible

Lekéri vagy beállít egy értéket, amely jelzi, hogy ez a menüelem látható-e.

Metódusok

Name Description
Equals(Object)

Meghatározza, hogy a megadott objektum egyenlő-e az aktuális objektummal.

(Öröklődés forrása Object)
GetHashCode()

Ez az alapértelmezett kivonatoló függvény.

(Öröklődés forrása Object)
GetType()

Lekéri az Type aktuális példányt.

(Öröklődés forrása Object)
Invoke()

Meghívja a parancsot.

Invoke(Object)

Meghívja a parancsot a megadott paraméterrel.

MemberwiseClone()

Az aktuális Objectpéldány sekély másolatát hozza létre.

(Öröklődés forrása Object)
OnCommandChanged(EventArgs)

Az eseményt emeli CommandChanged ki.

ToString()

Ennek a menüparancsnak a sztringképét adja vissza.

esemény

Name Description
CommandChanged

A menüparancs módosításakor következik be.

A következőre érvényes:

Lásd még