--- title: "How to: Handle the ContextMenuStrip Opening Event" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "ContextMenuStrip control [Windows Forms]" - "context menus [Windows Forms], event handling" - "ToolStrip control [Windows Forms]" - "event handling [Windows Forms], context menus" - "shortcut menus [Windows Forms], event handling" ms.assetid: b661b3dd-7815-4cc2-a1aa-a9a391ab3427 --- # How to: Handle the ContextMenuStrip Opening Event You can customize the behavior of your control by handling the event. ## Example The following code example demonstrates how to handle the event. The event handler adds items dynamically to a control. For the complete code example, see [How to: Add ToolStrip Items Dynamically](how-to-add-toolstrip-items-dynamically.md). [!code-csharp[System.Windows.Forms.ToolStrip.Misc#42](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.ToolStrip.Misc/CS/Program.cs#42)] [!code-vb[System.Windows.Forms.ToolStrip.Misc#42](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.ToolStrip.Misc/VB/Program.vb#42)] Set the property to `true` to prevent the menu from opening. ## See also - - - - [ToolStrip Control](toolstrip-control-windows-forms.md)