Share via


ContextMenu.Popup Olay

Tanım

Kısayol menüsü görüntülenmeden önce gerçekleşir.

public:
 event EventHandler ^ Popup;
public event EventHandler Popup;
member this.Popup : EventHandler 
Public Custom Event Popup As EventHandler 

Olay Türü

Örnekler

Aşağıdaki kod örneği, olayı için Popup bir olay işleyicisi ContextMenuoluşturur. Olay işleyicisindeki kod, iki denetimden PictureBox hangisinin bir adlandırılmış pictureBox1 ve hangilerinin TextBoxtextBox1 kısayol menüsünü görüntüleyen denetim olduğunu belirler. öğesinin ContextMenu kısayol menüsünü görüntülemesine neden olan denetime bağlı olarak, denetim uygun MenuItem nesneleri öğesine ContextMenuekler. Bu örnek, sınıfının formda tanımlanan adlı contextMenu1bir örneğine ContextMenu sahip olmasını gerektirir. Bu örnek ayrıca forma bir TextBox ve PictureBox ekleyip bu denetimlerin ContextMenu özelliğinin olarak ayarlanmasını contextMenu1gerektirir.

private:
   void MyPopupEventHandler( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Define the MenuItem objects to display for the TextBox.
      MenuItem^ menuItem1 = gcnew MenuItem( "&Copy" );
      MenuItem^ menuItem2 = gcnew MenuItem( "&Find and Replace" );
      // Define the MenuItem object to display for the PictureBox.
      MenuItem^ menuItem3 = gcnew MenuItem( "C&hange Picture" );
      
      // Clear all previously added MenuItems.
      contextMenu1->MenuItems->Clear();

      if ( contextMenu1->SourceControl == textBox1 )
      {
         
         // Add MenuItems to display for the TextBox.
         contextMenu1->MenuItems->Add( menuItem1 );
         contextMenu1->MenuItems->Add( menuItem2 );
      }
      else if ( contextMenu1->SourceControl == pictureBox1 )
      {
         // Add the MenuItem to display for the PictureBox.
         contextMenu1->MenuItems->Add( menuItem3 );
      }
   }
private void MyPopupEventHandler(System.Object sender, System.EventArgs e)
 {
    // Define the MenuItem objects to display for the TextBox.
    MenuItem menuItem1 = new MenuItem("&Copy");
    MenuItem menuItem2 = new MenuItem("&Find and Replace");
    // Define the MenuItem object to display for the PictureBox.
    MenuItem menuItem3 = new MenuItem("C&hange Picture");

    // Clear all previously added MenuItems.
    contextMenu1.MenuItems.Clear();
 
    if(contextMenu1.SourceControl == textBox1)
    {
       // Add MenuItems to display for the TextBox.
       contextMenu1.MenuItems.Add(menuItem1);
       contextMenu1.MenuItems.Add(menuItem2);
    }
    else if(contextMenu1.SourceControl == pictureBox1)
    {
       // Add the MenuItem to display for the PictureBox.
       contextMenu1.MenuItems.Add(menuItem3);
    }
 }
Private Sub MyPopupEventHandler(sender As System.Object, e As System.EventArgs)
    ' Define the MenuItem objects to display for the TextBox.
    Dim menuItem1 As New MenuItem("&Copy")
    Dim menuItem2 As New MenuItem("&Find and Replace")
    ' Define the MenuItem object to display for the PictureBox.
    Dim menuItem3 As New MenuItem("C&hange Picture")
    
    ' Clear all previously added MenuItems.
    contextMenu1.MenuItems.Clear()
    
    If contextMenu1.SourceControl Is textBox1 Then
        ' Add MenuItems to display for the TextBox.
        contextMenu1.MenuItems.Add(menuItem1)
        contextMenu1.MenuItems.Add(menuItem2)
    ElseIf contextMenu1.SourceControl Is pictureBox1 Then
        ' Add the MenuItem to display for the PictureBox.
        contextMenu1.MenuItems.Add(menuItem3)
    End If
End Sub

Açıklamalar

Nesneleri görüntülenmeden önce başlatmak MenuItem için bu olayı kullanabilirsiniz. Örneğin, üç TextBox denetim için bir ContextMenu kullanıyorsanız ve kısayol menüsünün görüntülendiğine bağlı TextBox olarak içindeki bazı menü öğelerini ContextMenu devre dışı bırakmak istiyorsanız, bu olay için bir olay işleyicisi oluşturabilirsiniz. özelliğini kullanarak SourceControl uygun TextBoxMenuItem nesneleri görüntülemek ContextMenu ve devre dışı bırakmak üzere olan nesneyi belirleyebilirsiniz.

Olayları işleme hakkında daha fazla bilgi için bkz. Olayları İşleme ve Oluşturma.

Şunlara uygulanır