---
title: Add and Remove Menu Items with ContextMenu Component
ms.date: "03/30/2017"
dev_langs: 
  - "csharp"
  - "vb"
  - "cpp"
helpviewer_keywords: 
  - "context menus [Windows Forms], removing items"
  - "ContextMenu component [Windows Forms], adding items"
  - "shortcut menus [Windows Forms], removing items"
  - "shortcut menus [Windows Forms], examples"
  - "context menus [Windows Forms], adding items"
  - "shortcut menus [Windows Forms], adding items"
  - "ContextMenu component [Windows Forms], removing items"
  - "context menus [Windows Forms], examples"
  - "examples [Windows Forms], context menus"
ms.assetid: 426d1eaf-7fb8-4b0b-8a33-5e8721786ea4
---
# How to: Add and Remove Menu Items with the Windows Forms ContextMenu Component
Explains how to add and remove shortcut menu items in Windows Forms.  
  
 The Windows Forms <xref:System.Windows.Forms.ContextMenu> component provides a menu of frequently used commands that are relevant to the selected object. You can add items to the shortcut menu by adding <xref:System.Windows.Forms.MenuItem> objects to the <xref:System.Windows.Forms.Menu.MenuItems%2A> collection.  
  
 You can remove items from a shortcut menu permanently; however, at run time it may be more appropriate to hide or disable the items instead.  
  
> [!IMPORTANT]
> Although <xref:System.Windows.Forms.MenuStrip> and <xref:System.Windows.Forms.ContextMenuStrip> replace and add functionality to the <xref:System.Windows.Forms.MainMenu> and <xref:System.Windows.Forms.ContextMenu> controls of previous versions, <xref:System.Windows.Forms.MainMenu> and <xref:System.Windows.Forms.ContextMenu> are retained for both backward compatibility and future use if you choose.  
  
### To remove items from a shortcut menu  
  
1. Use the <xref:System.Windows.Forms.Menu.MenuItemCollection.Remove%2A> or <xref:System.Windows.Forms.Menu.MenuItemCollection.RemoveAt%2A> method of the <xref:System.Windows.Forms.Menu.MenuItems%2A> collection of the <xref:System.Windows.Forms.ContextMenu> component to remove a particular menu item.  
  
    ```vb  
    ' Removes the first item in the shortcut menu.  
    ContextMenu1.MenuItems.RemoveAt(0)  
    ' Removes a particular object from the shortcut menu.  
    ContextMenu1.MenuItems.Remove(mnuItemNew)  
    ```  
  
    ```csharp  
    // Removes the first item in the shortcut menu.  
    contextMenu1.MenuItems.RemoveAt(0);  
    // Removes a particular object from the shortcut menu.  
    contextMenu1.MenuItems.Remove(mnuItemNew);  
    ```  
  
    ```cpp  
    // Removes the first item in the shortcut menu.  
    contextMenu1->MenuItems->RemoveAt(0);  
    // Removes a particular object from the shortcut menu.  
    contextMenu1->MenuItems->Remove(mnuItemNew);  
    ```  
  
     -or-  
  
2. Use the `Clear` method of the `MenuItems` collection of the <xref:System.Windows.Forms.ContextMenu> component to remove all items from the menu.  
  
    ```vb  
    ContextMenu1.MenuItems.Clear()  
    ```  
  
    ```csharp  
    contextMenu1.MenuItems.Clear();  
    ```  
  
    ```cpp  
    contextMenu1->MenuItems->Clear();  
    ```  
  
## See also

- <xref:System.Windows.Forms.ContextMenu>
- [ContextMenu Component](contextmenu-component-windows-forms.md)
- [ContextMenu Component Overview](contextmenu-component-overview-windows-forms.md)
