title | description | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
How to: Handle the ContextMenuStrip Opening Event |
Learn how to handle the ContextMenuStrip Opening event, which adds items dynamically to a ContextMenuStrip control. |
03/30/2017 |
|
|
b661b3dd-7815-4cc2-a1aa-a9a391ab3427 |
You can customize the behavior of your xref:System.Windows.Forms.ContextMenuStrip control by handling the xref:System.Windows.Forms.ToolStripDropDown.Opening event.
The following code example demonstrates how to handle the xref:System.Windows.Forms.ToolStripDropDown.Opening event. The event handler adds items dynamically to a xref:System.Windows.Forms.ContextMenuStrip control. For the complete code example, see How to: Add ToolStrip Items Dynamically.
[!code-csharpSystem.Windows.Forms.ToolStrip.Misc#42] [!code-vbSystem.Windows.Forms.ToolStrip.Misc#42]
Set the xref:System.ComponentModel.CancelEventArgs.Cancel%2A?displayProperty=nameWithType property to true
to prevent the menu from opening.
- xref:System.Windows.Forms.ContextMenuStrip
- xref:System.ComponentModel.CancelEventArgs.Cancel%2A
- xref:System.Windows.Forms.ToolStripDropDown
- ToolStrip Control