ContextMenu.Show Method (Control, Point)


Displays the shortcut menu at the specified position.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public void Show(
	Control control,
	Point pos


Type: System.Windows.Forms.Control

A Control that specifies the control with which this shortcut menu is associated.

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

The control parameter is null.


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. 
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));

.NET Framework
Available since 1.1
Return to top