Occurs before a menu item's list of menu items is displayed.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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 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 Sub PopupMyMenu(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuEdit.Popup If textBox1.Enabled = False OrElse textBox1.Focused = False OrElse textBox1.SelectedText.Length = 0 Then menuCut.Enabled = False menuCopy.Enabled = False menuDelete.Enabled = False Else menuCut.Enabled = True menuCopy.Enabled = True menuDelete.Enabled = True End If End Sub
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.