다음을 통해 공유


MenuCommand 클래스

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

네임스페이스: System.ComponentModel.Design
어셈블리: System(system.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
Public Class MenuCommand
‘사용 방법
Dim instance As MenuCommand
[ComVisibleAttribute(true)] 
public class MenuCommand
[ComVisibleAttribute(true)] 
public ref class MenuCommand
/** @attribute ComVisibleAttribute(true) */ 
public class MenuCommand
ComVisibleAttribute(true) 
public class MenuCommand

설명

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

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

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

  • 명령을 고유하게 식별하는 CommandID 속성

  • 명령을 실행하는 Invoke 메서드

  • 새 명령을 선택한 경우 발생하는 이벤트를 처리하기 위해 재정의할 수 있는 OnCommandChanged 메서드

  • 명령이 Checked, Enabled, Supported 또는 Visible인지 여부를 나타내는 부울 플래그

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

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

참고

이 클래스에 적용되는 HostProtectionAttribute 특성의 Resources 속성 값은 SharedState입니다. HostProtectionAttribute는 대개 아이콘을 두 번 클릭하거나, 명령을 입력하거나, 브라우저에서 URL을 입력하여 시작되는 데스크톱 응용 프로그램에 영향을 미치지 않습니다. 자세한 내용은 HostProtectionAttribute 클래스나 SQL Server 프로그래밍 및 호스트 보호 특성을 참조하십시오.

예제

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

폼에 Component1 클래스의 인스턴스를 만들고 Visual Studio 같은 디자인 환경에서 폼을 엽니다. MenuCommand를 호출하려면 F1 키를 누릅니다.

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
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.");
        }
    }
} 
#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." );
      }
   };
}

.NET Framework 보안

상속 계층 구조

System.Object
  System.ComponentModel.Design.MenuCommand
     System.ComponentModel.Design.DesignerVerb

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

MenuCommand 멤버
System.ComponentModel.Design 네임스페이스
StandardCommands
IMenuCommandService 인터페이스
CommandID 클래스

기타 리소스

Windows Forms용 디자이너 명령 및 DesignerAction 개체 모델