ContextMenu Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy ContextMenu.

Przeciążenia

ContextMenu()

Inicjuje ContextMenu nowe wystąpienie klasy bez określonych elementów menu.

ContextMenu(MenuItem[])

Inicjuje ContextMenu nowe wystąpienie klasy z określonym zestawem MenuItem obiektów.

ContextMenu()

Inicjuje ContextMenu nowe wystąpienie klasy bez określonych elementów menu.

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

Uwagi

Po użyciu tej wersji konstruktora można dodać elementy menu do ContextMenu klasy przy użyciu Add metody Menu.MenuItemCollection klasy . Dostęp do obiektu można uzyskać Menu.MenuItemCollection za pośrednictwem MenuItems właściwości .

Zobacz też

Dotyczy

ContextMenu(MenuItem[])

Inicjuje ContextMenu nowe wystąpienie klasy z określonym zestawem MenuItem obiektów.

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())

Parametry

menuItems
MenuItem[]

Tablica MenuItem obiektów reprezentujących elementy menu, które mają zostać dodane do menu skrótów.

Przykłady

Poniższy przykład kodu przedstawia konstruowanie menu skrótów i używanie Show metody . Aby uruchomić przykład, wklej następujący kod w formularzu zawierający przycisk o nazwie Button1. Upewnij się, że wszystkie zdarzenia są skojarzone z ich metodami obsługi zdarzeń.

// 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

Uwagi

Możesz użyć tej wersji konstruktora, aby utworzyć element ContextMenu menu zawierający elementy menu określone w momencie jego utworzenia. Po użyciu tej wersji konstruktora można dodać do klasy dodatkowe elementy ContextMenu menu przy użyciu Add metody Menu.MenuItemCollection klasy . Dostęp do obiektu można uzyskać Menu.MenuItemCollection za pośrednictwem MenuItems właściwości .

Zobacz też

Dotyczy