ContextMenu Constructor (array<MenuItem^>^)
.NET Framework (current version)
Initializes a new instance of the ContextMenu class with a specified set of MenuItem objects.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
You can use this version of the constructor to create a ContextMenu that has its menu items specified at the time it is created. Once you have used this version of the constructor, you can add additional menu items to the ContextMenu by using the Add method of the Menu::MenuItemCollection class. You can access the Menu::MenuItemCollection through the MenuItems property.
The following code example demonstrates constructing a shortcut menu and using the Show method. To run the example, paste the following code in a form containing a button named Button1. Ensure all events are associated with their event-handling methods.
// 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 ) ); }
.NET Framework
Available since 1.1
Available since 1.1
Show: