ContextMenu Component Overview (Windows Forms)

NoteImportant

Although MenuStrip and ContextMenuStrip replace and add functionality to the MainMenu and ContextMenu controls of previous versions, MainMenu and ContextMenu are retained for both backward compatibility and future use if you choose.

With the Windows Forms ContextMenu component, you can provide users with an easily accessible shortcut menu of frequently used commands that are associated with the selected object. The items in a shortcut menu are frequently a subset of the items from main menus that appear elsewhere in the application. A user can typically access a shortcut menu by right-clicking the mouse. On Windows Forms, shortcut menus are associated with controls.

Key Properties

You can associate a shortcut menu with a control by setting the control's ContextMenu property to the ContextMenu component. A single shortcut menu can be associated with multiple controls, but each control can have only one shortcut menu.

The key property of the ContextMenu component is the MenuItems property. You can add menu items by programmatically creating MenuItem objects and adding them to the MenuItemCollection of the shortcut menu. Because the items in a shortcut menu are usually drawn from other menus, you will most frequently add items to a shortcut menu by copying them.

See Also

Reference

ContextMenu
MenuStrip
ContextMenuStrip