--- 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 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 objects to the 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 and replace and add functionality to the and controls of previous versions, and are retained for both backward compatibility and future use if you choose. ### To remove items from a shortcut menu 1. Use the or method of the collection of the 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 component to remove all items from the menu. ```vb ContextMenu1.MenuItems.Clear() ``` ```csharp contextMenu1.MenuItems.Clear(); ``` ```cpp contextMenu1->MenuItems->Clear(); ``` ## See also - - [ContextMenu Component](contextmenu-component-windows-forms.md) - [ContextMenu Component Overview](contextmenu-component-overview-windows-forms.md)