ContextMenu Конструкторы

Определение

Инициализирует новый экземпляр класса ContextMenu.

Перегрузки

ContextMenu()

Инициализирует новый экземпляр класса ContextMenu без указания команд меню.

ContextMenu(MenuItem[])

Инициализирует новый экземпляр класса ContextMenu с указанным набором объектов MenuItem.

ContextMenu()

Инициализирует новый экземпляр класса ContextMenu без указания команд меню.

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

Комментарии

После использования этой версии конструктора можно добавить пункты меню в ContextMenu с помощью Add метода Menu.MenuItemCollection класса . Доступ к можно получить через Menu.MenuItemCollectionMenuItems свойство .

См. также раздел

Применяется к

ContextMenu(MenuItem[])

Инициализирует новый экземпляр класса ContextMenu с указанным набором объектов 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())

Параметры

menuItems
MenuItem[]

Массив объектов MenuItem, представляющих добавляемые в контекстное меню команды.

Примеры

В следующем примере кода показано создание контекстного меню и использование Show метода . Чтобы выполнить пример, вставьте следующий код в форму, содержащую кнопку с именем Button1. Убедитесь, что все события связаны с их методами обработки событий.

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

Комментарии

Эту версию конструктора можно использовать для создания ContextMenu объекта , элементы меню которого указаны во время его создания. После использования этой версии конструктора можно добавить дополнительные пункты меню в ContextMenu с помощью Add метода Menu.MenuItemCollection класса . Доступ к можно получить через Menu.MenuItemCollectionMenuItems свойство .

См. также раздел

Применяется к