ContextMenu::Show Method (Control^, Point)
Displays the shortcut menu at the specified position.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- control
-
Type:
System.Windows.Forms::Control^
A Control that specifies the control with which this shortcut menu is associated.
- pos
-
Type:
System.Drawing::Point
A Point that specifies the coordinates at which to display the menu. These coordinates are specified relative to the client coordinates of the control specified in the control parameter.
| Exception | Condition |
|---|---|
| ArgumentNullException | The control parameter is null. |
| ArgumentException | The handle of the control does not exist or the control is not visible. |
Typically, a ContextMenu is displayed when the user clicks the right mouse button on a control or area of the form that the ContextMenu is bound to. You can use this method to manually display the shortcut menu at a specific location and bind it with a specific control. This method does not return until the menu is dismissed.
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 ) ); }
Available since 1.1