Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ContextMenuStrip Class

Note: This class is new in the .NET Framework version 2.0.

Represents a shortcut menu.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class ContextMenuStrip : public ToolStripDropDownMenu
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class ContextMenuStrip extends ToolStripDropDownMenu
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class ContextMenuStrip extends ToolStripDropDownMenu

The ContextMenuStrip class represents shortcut menus that are displayed when the user clicks the right mouse button over a control or area of the form. Shortcut menus are typically used to combine different menu items from a MenuStrip of a form that are useful for the user given the context of the application. For example, you can use a shortcut menu assigned to a TextBox control to provide menu items for changing the font of the text, finding text within the control, or Clipboard features for copying and pasting text. You can also expose new ToolStripMenuItem objects in a shortcut menu that are not located within a MenuStrip to provide situation-specific commands that are inappropriate for the MenuStrip to display.

Typically, a shortcut menu is displayed when a user clicks the right mouse button over a control or the form itself. Many visible controls, as well as the Form itself, have a Control.ContextMenuStrip property that binds the ContextMenuStrip class to the control that displays the shortcut menu. More than one control can use a ContextMenuStrip.

Set the ToolStripDropDownMenu.ShowCheckMargin property to true to add space to the left of a ToolStripMenuItem for a check mark that shows that the menu item is enabled or selected. The ToolStripDropDownMenu.ShowImageMargin property is set to true by default. Use this space to the left of the ToolStripMenuItem to display an image for that menu item.

ContextMenuStrip is the container for ToolStripMenuItem, ToolStripComboBox, ToolStripSeparator, and ToolStripTextBox objects.

Although ContextMenuStrip replaces and adds functionality to the ContextMenu control of previous versions, ContextMenu is retained for both backward compatibility and future use if so desired.

The following code example demonstrates a ContextMenuStrip with dynamic item addition, dynamic SourceControl determination with reuse, and handling of the Opening event.

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

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ToolStrip
             System.Windows.Forms.ToolStripDropDown
               System.Windows.Forms.ToolStripDropDownMenu
                System.Windows.Forms.ContextMenuStrip

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft