Edit

Share via


MenuItem.OnPopup(EventArgs) Method

Definition

Raises the Popup event.

protected:
 virtual void OnPopup(EventArgs ^ e);
protected virtual void OnPopup (EventArgs e);
abstract member OnPopup : EventArgs -> unit
override this.OnPopup : EventArgs -> unit
Protected Overridable Sub OnPopup (e As EventArgs)

Parameters

e
EventArgs

An EventArgs that contains the event data.

Examples

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.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 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

Remarks

Raising an event invokes the event handler through a delegate. For more information, see Handling and Raising Events.

Notes to Inheritors

When overriding OnPopup(EventArgs) in a derived class, be sure to call the base class's OnPopup(EventArgs) method.

Applies to