Export (0) Print
Expand All

Menu.GetContextMenu Method

Gets the ContextMenu that contains this menu.

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

member GetContextMenu : unit -> ContextMenu 

Return Value

Type: System.Windows.Forms.ContextMenu
The ContextMenu that contains this menu. The default is a null reference (Nothing in Visual Basic).

This method allows you to obtain a reference to the ContextMenu that this menu is contained in. This property returns a null reference (Nothing in Visual Basic) if the menu is not contained in a ContextMenu. This can occur if the menu is contained in a MenuItem or MainMenu, or if the menu is not contained in any menu. You can use this property to determine whether a menu is currently being used, and also to determine where.

In this example, you use the GetContextMenu method to obtain a reference to the shortcut menu that contains menuItem1 or menuItem2, and display the shortcut menu information in a message box. You programmatically create a shortcut menu with two items, New and Open. You then add functionality to these items by creating the appropriate event handlers. When you run the example, you get a message box that tells you to right-click the form in order to display the shortcut menu. Then, when you click a menu item, you get another message that tells which item has been clicked and displays the information on the containing shortcut menu. This example requires that you have already created a Form named Form1.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft