ContextMenu Konstruktorok

Definíció

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

Túlterhelések

Name Description
ContextMenu()

Inicializálja az osztály új példányát, ContextMenu amelyben nincsenek megadva menüelemek.

ContextMenu(MenuItem[])

Inicializálja az ContextMenu osztály új példányát egy meghatározott objektumkészlettel MenuItem .

ContextMenu()

Forrás:
ContextMenu.cs
Forrás:
ContextMenu.cs

Inicializálja az osztály új példányát, ContextMenu amelyben nincsenek megadva menüelemek.

public:
 ContextMenu();
public ContextMenu();
Public Sub New ()

Megjegyzések

Miután felhasználta a konstruktor ezen verzióját, az osztály metódusával ContextMenu hozzáadhat menüelemeket a Add programhozMenu.MenuItemCollection. A tulajdonságon keresztül Menu.MenuItemCollection is hozzáférhetMenuItems.

Lásd még

A következőre érvényes:

ContextMenu(MenuItem[])

Forrás:
ContextMenu.cs
Forrás:
ContextMenu.cs

Inicializálja az ContextMenu osztály új példányát egy meghatározott objektumkészlettel MenuItem .

public:
 ContextMenu(cli::array <System::Windows::Forms::MenuItem ^> ^ menuItems);
public ContextMenu(System.Windows.Forms.MenuItem[] menuItems);
new System.Windows.Forms.ContextMenu : System.Windows.Forms.MenuItem[] -> System.Windows.Forms.ContextMenu
Public Sub New (menuItems As MenuItem())

Paraméterek

menuItems
MenuItem[]

A helyi menübe felvenni kívánt menüelemeket ábrázoló objektumtömb MenuItem .

Példák

Az alábbi példakód egy helyi menü felépítését és a Show metódus használatát mutatja be. A példa futtatásához illessze be a következő kódot egy button1 nevű gombot tartalmazó űrlapba. Győződjön meg arról, hogy minden esemény társítva van az eseménykezelési módszereikkel.

// Displays the shortcut menu, offsetting its location 
// from the upper-left corner of Button1 by 20 pixels in each direction. 
void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   
   //Declare the menu items and the shortcut menu.
   array<MenuItem^>^menuItems = {gcnew MenuItem( "Some Button Info" ),gcnew MenuItem( "Some Other Button Info" ),gcnew MenuItem( "Exit" )};
   System::Windows::Forms::ContextMenu^ buttonMenu = gcnew System::Windows::Forms::ContextMenu( menuItems );
   buttonMenu->Show( Button1, System::Drawing::Point( 20, 20 ) );
}

// Displays the shortcut menu, offsetting its location 
// from the upper-left corner of Button1 by 20 pixels in each direction. 
private void Button1_Click(System.Object sender, System.EventArgs e)
{

    //Declare the menu items and the shortcut menu.
    MenuItem[] menuItems = new MenuItem[]{new MenuItem("Some Button Info"), 
        new MenuItem("Some Other Button Info"), new MenuItem("Exit")};

    ContextMenu buttonMenu = new ContextMenu(menuItems);
    buttonMenu.Show(Button1, new System.Drawing.Point(20, 20));
}

' Displays the shortcut menu, offsetting its location 
' from the upper-left corner of Button1 by 20 pixels in each direction. 
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    'Declare the menu items and the shortcut menu.
    Dim menuItems() As MenuItem = New MenuItem() _
        {New MenuItem("Some Button Info"), _
        New MenuItem("Some Other Button Info"), _
        New MenuItem("Exit")}

    Dim buttonMenu As New ContextMenu(menuItems)
    buttonMenu.Show(Button1, New System.Drawing.Point(20, 20))
End Sub

Megjegyzések

A konstruktor ezen verziójával létrehozhat egy ContextMenu olyan menüelemet, amely a létrehozáskor meg van adva. A konstruktor ezen verziójának használata után további menüelemeket adhat hozzá az ContextMenuAddMenu.MenuItemCollection osztály metódusával. A tulajdonságon keresztül Menu.MenuItemCollection is hozzáférhetMenuItems.

Lásd még

A következőre érvényes: