다음을 통해 공유


ContextMenu 클래스

정의

주의

ContextMenu is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use ContextMenuStrip instead.

바로 가기 메뉴를 나타냅니다.

이 클래스는 .NET Core 3.1 이상 버전에서는 사용할 수 없습니다. ContextMenuStrip 대신 컨트롤을 바꾸고 확장합니다ContextMenu.

public ref class ContextMenu : System::Windows::Forms::Menu
public class ContextMenu : System.Windows.Forms.Menu
[System.ComponentModel.Browsable(false)]
[System.Obsolete("`ContextMenu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ContextMenuStrip` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
public class ContextMenu : System.Windows.Forms.Menu
type ContextMenu = class
    inherit Menu
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("`ContextMenu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ContextMenuStrip` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
type ContextMenu = class
    inherit Menu
Public Class ContextMenu
Inherits Menu
상속
특성

예제

다음 코드 예제에서는 이벤트에 대 한 Popup 이벤트 ContextMenu처리기를 만듭니다. 이벤트 처리기의 코드는 명명된 컨트롤과 TextBox 명명 pictureBox1textBox1 된 컨트롤 PictureBox 중 바로 가기 메뉴를 표시하는 컨트롤을 결정합니다. 해당 바로 가기 메뉴를 표시 하는 컨트롤에 ContextMenu 따라 컨트롤에 적절 MenuItem 한 개체를 ContextMenu추가 합니다. 이 예제에서는 양식 내에 정의된 클래스contextMenu1ContextMenu 인스턴스가 있어야 합니다. 또한 이 예제에서는 폼에 추가한 컨트롤의 속성이 />로 설정되어 있어야 합니다.

private:
   void MyPopupEventHandler( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Define the MenuItem objects to display for the TextBox.
      MenuItem^ menuItem1 = gcnew MenuItem( "&Copy" );
      MenuItem^ menuItem2 = gcnew MenuItem( "&Find and Replace" );
      // Define the MenuItem object to display for the PictureBox.
      MenuItem^ menuItem3 = gcnew MenuItem( "C&hange Picture" );
      
      // Clear all previously added MenuItems.
      contextMenu1->MenuItems->Clear();

      if ( contextMenu1->SourceControl == textBox1 )
      {
         
         // Add MenuItems to display for the TextBox.
         contextMenu1->MenuItems->Add( menuItem1 );
         contextMenu1->MenuItems->Add( menuItem2 );
      }
      else if ( contextMenu1->SourceControl == pictureBox1 )
      {
         // Add the MenuItem to display for the PictureBox.
         contextMenu1->MenuItems->Add( menuItem3 );
      }
   }
private void MyPopupEventHandler(System.Object sender, System.EventArgs e)
 {
    // Define the MenuItem objects to display for the TextBox.
    MenuItem menuItem1 = new MenuItem("&Copy");
    MenuItem menuItem2 = new MenuItem("&Find and Replace");
    // Define the MenuItem object to display for the PictureBox.
    MenuItem menuItem3 = new MenuItem("C&hange Picture");

    // Clear all previously added MenuItems.
    contextMenu1.MenuItems.Clear();
 
    if(contextMenu1.SourceControl == textBox1)
    {
       // Add MenuItems to display for the TextBox.
       contextMenu1.MenuItems.Add(menuItem1);
       contextMenu1.MenuItems.Add(menuItem2);
    }
    else if(contextMenu1.SourceControl == pictureBox1)
    {
       // Add the MenuItem to display for the PictureBox.
       contextMenu1.MenuItems.Add(menuItem3);
    }
 }
Private Sub MyPopupEventHandler(sender As System.Object, e As System.EventArgs)
    ' Define the MenuItem objects to display for the TextBox.
    Dim menuItem1 As New MenuItem("&Copy")
    Dim menuItem2 As New MenuItem("&Find and Replace")
    ' Define the MenuItem object to display for the PictureBox.
    Dim menuItem3 As New MenuItem("C&hange Picture")
    
    ' Clear all previously added MenuItems.
    contextMenu1.MenuItems.Clear()
    
    If contextMenu1.SourceControl Is textBox1 Then
        ' Add MenuItems to display for the TextBox.
        contextMenu1.MenuItems.Add(menuItem1)
        contextMenu1.MenuItems.Add(menuItem2)
    ElseIf contextMenu1.SourceControl Is pictureBox1 Then
        ' Add the MenuItem to display for the PictureBox.
        contextMenu1.MenuItems.Add(menuItem3)
    End If
End Sub

설명

이 클래스는 .NET Core 3.1 이상 버전에서는 사용할 수 없습니다. ContextMenuStrip를 대신 사용하세요.

클래스는 ContextMenu 사용자가 폼의 컨트롤이나 영역에서 마우스 오른쪽 단추를 클릭할 때 표시할 수 있는 바로 가기 메뉴를 나타냅니다. 바로 가기 메뉴는 일반적으로 애플리케이션의 컨텍스트를 고려할 때 사용자에게 유용한 양식의 다양한 메뉴 항목을 MainMenu 결합하는 데 사용됩니다. 예를 들어 컨트롤에 TextBox 할당된 바로 가기 메뉴를 사용하여 텍스트의 글꼴 변경, 컨트롤 내의 텍스트 찾기 또는 텍스트 복사 및 붙여넣기용 클립보드 기능을 위한 메뉴 항목을 제공할 수 있습니다. 바로 가기 메뉴에 새 개체를 표시 MenuItem 하여 표시하기에 적합하지 MainMenu 않은 MainMenu 상황별 명령을 제공할 수도 있습니다.

일반적으로 바로 가기 메뉴는 사용자가 컨트롤 또는 양식 자체에 마우스 오른쪽 단추를 클릭할 때 표시됩니다. 표시되는 컨트롤과 FormContextMenu 바로 가기 메뉴를 표시하는 컨트롤에 ContextMenu 클래스를 바인딩하는 속성이 있습니다. 둘 이상의 컨트롤에서 .를 ContextMenu사용할 수 있습니다. 컨트롤과 SourceControl 관련된 작업을 수행하거나 컨트롤에 대해 표시되는 바로 가기 메뉴를 수정하기 위해 이 속성을 사용하여 바로 가기 메뉴를 마지막으로 표시한 컨트롤을 확인할 수 있습니다.

사용자에게 메뉴가 표시되기 전에 확인 표시를 설정하고, 항목을 사용하지 않도록 설정하고, 다른 메뉴 작업을 수행하기 위해 바로 가기 메뉴가 표시되는 시기를 알고 싶을 수 있습니다. 이벤트를 처리 Popup 하여 바로 가기 메뉴가 표시되는 시기를 확인할 수 있습니다.

메모

에 사용할 개체 MainMenu 를 다시 사용 MenuItemContextMenu하려면 클래스의 메서드 MenuItem 를 사용하여 메뉴의 복사본을 CloneMenu 만들어야 합니다. 또한 클래스의 메서드를 사용하여 메뉴 항목과 해당 하위 메뉴 항목을 단일 MenuItem 개체로 병합할 MergeMenuMenuItem 수 있습니다.

생성자

Name Description
ContextMenu()
사용되지 않음.

메뉴 항목이 지정되지 않은 상태에서 클래스의 ContextMenu 새 인스턴스를 초기화합니다.

ContextMenu(MenuItem[])
사용되지 않음.

지정된 개체 집합 MenuItem 을 사용하여 클래스의 ContextMenu 새 인스턴스를 초기화합니다.

필드

Name Description
FindHandle
사용되지 않음.

메서드가 핸들을 FindMenuItem(Int32, IntPtr) 검색할 수 있도록 지정합니다.

(다음에서 상속됨 Menu)
FindShortcut
사용되지 않음.

메서드가 바로 가기를 FindMenuItem(Int32, IntPtr) 검색할 수 있도록 지정합니다.

(다음에서 상속됨 Menu)

속성

Name Description
CanRaiseEvents
사용되지 않음.

구성 요소가 이벤트를 발생시키는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
Container
사용되지 않음.

IContainer 포함하는 값을 가져옵니다 Component.

(다음에서 상속됨 Component)
DesignMode
사용되지 않음.

현재 디자인 모드인지 여부를 Component 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
Events
사용되지 않음.

Component에 연결된 이벤트 처리기 목록을 가져옵니다.

(다음에서 상속됨 Component)
Handle
사용되지 않음.

메뉴의 창 핸들을 나타내는 값을 가져옵니다.

(다음에서 상속됨 Menu)
IsParent
사용되지 않음.

이 메뉴에 메뉴 항목이 포함되어 있는지 여부를 나타내는 값을 가져옵니다. 이 속성은 읽기 전용입니다.

(다음에서 상속됨 Menu)
MdiListItem
사용되지 않음.

MDI(여러 문서 인터페이스) 자식 양식의 목록을 표시하는 데 사용되는 값을 가져옵니다 MenuItem .

(다음에서 상속됨 Menu)
MenuItems
사용되지 않음.

메뉴와 연결된 개체의 MenuItem 컬렉션을 나타내는 값을 가져옵니다.

(다음에서 상속됨 Menu)
Name
사용되지 않음.

의 이름을 Menu가져오거나 설정합니다.

(다음에서 상속됨 Menu)
RightToLeft
사용되지 않음.

컨트롤에 표시되는 텍스트가 오른쪽에서 왼쪽으로 표시되는지 여부를 나타내는 값을 가져오거나 설정합니다.

Site
사용되지 않음.

ISite값을 Component 가져오거나 설정합니다.

(다음에서 상속됨 Component)
SourceControl
사용되지 않음.

바로 가기 메뉴를 표시하는 컨트롤을 가져옵니다.

Tag
사용되지 않음.

컨트롤과 연결된 사용자 정의 데이터를 가져오거나 설정합니다.

(다음에서 상속됨 Menu)

메서드

Name Description
CloneMenu(Menu)
사용되지 않음.

Menu 매개 변수로 전달된 값을 현재Menu에 복사합니다.

(다음에서 상속됨 Menu)
CreateMenuHandle()
사용되지 않음.

에 대한 새 핸들을 Menu만듭니다.

(다음에서 상속됨 Menu)
CreateObjRef(Type)
사용되지 않음.

원격 개체와 통신하는 데 사용되는 프록시를 생성하는 데 필요한 모든 관련 정보를 포함하는 개체를 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Dispose()
사용되지 않음.

에서 사용하는 모든 리소스를 Component해제합니다.

(다음에서 상속됨 Component)
Dispose(Boolean)
사용되지 않음.

에서 사용하는 메모리 이외의 리소스를 Menu삭제합니다.

(다음에서 상속됨 Menu)
Equals(Object)
사용되지 않음.

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

(다음에서 상속됨 Object)
FindMenuItem(Int32, IntPtr)
사용되지 않음.

MenuItem 지정된 값을 포함하는 값을 가져옵니다.

(다음에서 상속됨 Menu)
FindMergePosition(Int32)
사용되지 않음.

메뉴 항목이 메뉴에 삽입되어야 하는 위치를 반환합니다.

(다음에서 상속됨 Menu)
GetContextMenu()
사용되지 않음.

이 메뉴가 ContextMenu 포함된 항목을 가져옵니다.

(다음에서 상속됨 Menu)
GetHashCode()
사용되지 않음.

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 현재 수명 서비스 개체를 검색합니다.

(다음에서 상속됨 MarshalByRefObject)
GetMainMenu()
사용되지 않음.

이 메뉴가 MainMenu 포함된 항목을 가져옵니다.

(다음에서 상속됨 Menu)
GetService(Type)
사용되지 않음.

또는 해당 서비스에서 제공하는 서비스를 나타내는 개체를 Component 반환합니다 Container.

(다음에서 상속됨 Component)
GetType()
사용되지 않음.

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

(다음에서 상속됨 Object)
InitializeLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다.

(다음에서 상속됨 MarshalByRefObject)
MemberwiseClone()
사용되지 않음.

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

(다음에서 상속됨 Object)
MemberwiseClone(Boolean)
사용되지 않음.

현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
MergeMenu(Menu)
사용되지 않음.

한 메뉴의 MenuItem 개체를 현재 메뉴와 병합합니다.

(다음에서 상속됨 Menu)
OnCollapse(EventArgs)
사용되지 않음.

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

OnPopup(EventArgs)
사용되지 않음.

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

ProcessCmdKey(Message, Keys, Control)
사용되지 않음.

명령 키를 처리합니다.

ProcessCmdKey(Message, Keys)
사용되지 않음.

명령 키를 처리합니다.

(다음에서 상속됨 Menu)
Show(Control, Point, LeftRightAlignment)
사용되지 않음.

지정된 위치와 지정된 맞춤을 사용하여 바로 가기 메뉴를 표시합니다.

Show(Control, Point)
사용되지 않음.

지정된 위치에 바로 가기 메뉴를 표시합니다.

ToString()
사용되지 않음.

컨트롤을 String 나타내는 값을 반환합니다 Menu .

(다음에서 상속됨 Menu)

이벤트

Name Description
Collapse
사용되지 않음.

바로 가기 메뉴가 축소되면 발생합니다.

Disposed
사용되지 않음.

구성 요소가 메서드 호출에 Dispose() 의해 삭제될 때 발생합니다.

(다음에서 상속됨 Component)
Popup
사용되지 않음.

바로 가기 메뉴가 표시되기 전에 발생합니다.

적용 대상

추가 정보