MenuCommand 클래스

정의

창 메뉴 또는 도구 모음 명령 항목을 나타냅니다.

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
상속
MenuCommand
파생
특성

예제

다음 코드 예제에서는 개체를 MenuCommand 만들고 해당 속성을 구성한 다음 에 추가합니다 IMenuCommandService.

양식에 클래스의 Component1 instance 만들고 Visual Studio와 같은 디자인 환경에서 양식을 엽니다. F1 키를 눌러 를 호출합니다 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

설명

클래스는 MenuCommand Windows 메뉴 또는 도구 모음 명령에 대한 정보를 나타냅니다. IMenuCommandService 인터페이스를 사용하면 Visual Studio 메뉴에 개체를 추가할 MenuCommand 수 있습니다.

이 클래스는 다음 멤버를 제공합니다.

  • 명령에 대한 이벤트 처리기를 연결할 수 있는 이벤트 처리기 속성입니다.

  • CommandID 명령을 고유하게 식별하는 속성입니다.

  • Invoke 명령을 실행하는 메서드입니다.

  • OnCommandChanged 새 명령을 선택할 때 발생하는 이벤트를 처리하기 위해 재정의할 수 있는 메서드입니다.

  • 명령Checked이 , , EnabledSupported또는 Visible인지 여부를 나타내는 부울 플래그 상태입니다.

  • OleStatus 명령에 대한 OLE 명령 상태 코드를 나타내는 속성입니다.

  • 메서드에 대한 재정의입니다 ToString .

생성자

MenuCommand(EventHandler, CommandID)

MenuCommand 클래스의 새 인스턴스를 초기화합니다.

속성

Checked

이 메뉴 항목이 선택되어 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

CommandID

이 메뉴 명령과 관련된 CommandID를 가져옵니다.

Enabled

이 메뉴 항목을 사용할 수 있는지 여부를 나타내는 값을 가져옵니다.

OleStatus

이 메뉴 항목에 대한 OLE 명령 상태 코드를 가져옵니다.

Properties

MenuCommand와 연결된 public 속성을 가져옵니다.

Supported

이 메뉴 항목이 지원되는지 여부를 나타내는 값을 가져오거나 설정합니다.

Visible

이 메뉴 항목이 표시되는지 여부를 나타내는 값을 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
Invoke()

명령을 호출합니다.

Invoke(Object)

지정한 매개 변수가 있는 명령을 호출합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnCommandChanged(EventArgs)

CommandChanged 이벤트를 발생시킵니다.

ToString()

이 메뉴 명령의 문자열 표현을 반환합니다.

이벤트

CommandChanged

메뉴 명령이 변경될 경우 발생합니다.

적용 대상

추가 정보