Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

MenuItem.Popup Event

Occurs before a menu item's list of menu items is displayed.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public event EventHandler Popup
/** @event */
public void add_Popup (EventHandler value)

/** @event */
public void remove_Popup (EventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

This event only occurs when a menu item has submenu items to display. You can use this event handler to add, remove, enable, disable, check, or uncheck menu items based on the state of your application before they are displayed. For more information about handling events, see Consuming Events.

The following code example demonstrates how to use the Popup event to determine whether MenuItem objects that provide support for cut, copy, and delete operations are enabled before the menu they are displayed in is shown. The example determines if textBox1, a TextBox control on the form, is enabled, has input focus, and has text selected before enabling the MenuItem objects. This example requires that three MenuItem objects are created named menuCut, menuCopy, and menuDelete have been created.

private void PopupMyMenu(object sender, System.EventArgs e)
{
   if (textBox1.Enabled == false || textBox1.Focused == false ||
      textBox1.SelectedText.Length == 0)
   {
      menuCut.Enabled = false;
      menuCopy.Enabled = false;
      menuDelete.Enabled = false;
   }
   else
   {
      menuCut.Enabled = true;
      menuCopy.Enabled = true;
      menuDelete.Enabled = true;
   }
}

private void PopupMyMenu(Object sender, System.EventArgs e)
{
    if (textBox1.get_Enabled() == false || textBox1.get_Focused() == false 
        || textBox1.get_SelectedText().get_Length() == 0) {
        menuCut.set_Enabled(false);
        menuCopy.set_Enabled(false);
        menuDelete.set_Enabled(false);
    }
    else {
        menuCut.set_Enabled(true);
        menuCopy.set_Enabled(true);
        menuDelete.set_Enabled(true);
    }
} //PopupMyMenu

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft