Export (0) Print
Expand All

MenuItem.OnPopup Method

Raises the Popup event.

[Visual Basic]
Protected Overridable Sub OnPopup( _
   ByVal e As EventArgs _
)
[C#]
protected virtual void OnPopup(
 EventArgs e
);
[C++]
protected: virtual void OnPopup(
 EventArgs* e
);
[JScript]
protected function OnPopup(
   e : EventArgs
);

Parameters

e
An EventArgs that contains the event data.

Remarks

Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

Notes to Inheritors:  When overriding OnPopup in a derived class, be sure to call the base class's OnPopup method.

Example

[Visual Basic, C#, C++] The following 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 assumes that three MenuItem objects are created named menuCut, menuCopy, and menuDelete have been created.

[Visual Basic] 
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

[C#] 
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;
   }
}

[C++] 
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;
      }
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

MenuItem Class | MenuItem Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft