ContextMenu.Popup Event

 

Occurs before the shortcut menu is displayed.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member Popup : IEvent<EventHandler,
    EventArgs>

You can use this event to initialize the MenuItem objects before they are displayed. For example, if you use a ContextMenu for three TextBox controls and you want to disable certain menu items in the ContextMenu depending on which TextBox is displaying the shortcut menu, you can create an event handler for this event. You could use the SourceControl property to determine which TextBox is about to display the ContextMenu and disable the appropriate MenuItem objects.

For more information about handling events, see Handling and Raising Events.

The following code example creates an event handler for the Popup event of the ContextMenu. The code in the event handler determines which of two controls a PictureBox named pictureBox1 and a TextBox named textBox1 is the control displaying the shortcut menu. Depending on which control caused the ContextMenu to display its shortcut menu, the control adds the appropriate MenuItem objects to the ContextMenu. This example requires that you have an instance of the ContextMenu class, named contextMenu1, defined within the form. This example also requires that you have a TextBox and PictureBox added to a form and that the ContextMenu property of these controls is set to contextMenu1.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: