Control.ContextMenu Właściwość

Definicja

Pobiera lub ustawia menu skrótów skojarzone z kontrolką.

public:
 virtual property System::Windows::Forms::ContextMenu ^ ContextMenu { System::Windows::Forms::ContextMenu ^ get(); void set(System::Windows::Forms::ContextMenu ^ value); };
public virtual System.Windows.Forms.ContextMenu ContextMenu { get; set; }
[System.ComponentModel.Browsable(false)]
public virtual System.Windows.Forms.ContextMenu ContextMenu { get; set; }
member this.ContextMenu : System.Windows.Forms.ContextMenu with get, set
[<System.ComponentModel.Browsable(false)>]
member this.ContextMenu : System.Windows.Forms.ContextMenu with get, set
Public Overridable Property ContextMenu As ContextMenu

Wartość właściwości

Element ContextMenu reprezentujący menu skrótów skojarzone z kontrolką.

Atrybuty

Przykłady

Poniższy przykład kodu wyświetla przypisany do obiektu TreeView po kliknięciu ContextMenu i zwolnieniu prawego przycisku myszy. Ten kod wymaga, aby element miał Form na nim element .TreeView Wymagane jest również, aby obiekt TreeView ma przypisaną ContextMenu właściwość ContextMenu .

private:
   void treeView1_MouseUp( Object^ /*sender*/, MouseEventArgs^ e )
   {
      // If the right mouse button was clicked and released,
      // display the shortcut menu assigned to the TreeView.
      if ( e->Button == ::MouseButtons::Right )
      {
         treeView1->ContextMenu->Show( treeView1, Point(e->X,e->Y) );
      }
   }
private void treeView1_MouseUp(object sender, MouseEventArgs e)
{
   // If the right mouse button was clicked and released,
   // display the shortcut menu assigned to the TreeView. 
   if(e.Button == MouseButtons.Right)
   {
      treeView1.ContextMenu.Show(treeView1, new Point(e.X, e.Y) );      
   }
}
Private Sub treeView1_MouseUp(sender As Object, _
  e As MouseEventArgs) Handles treeView1.MouseUp
   ' If the right mouse button was clicked and released,
   ' display the shortcut menu assigned to the TreeView. 
   If e.Button = MouseButtons.Right Then
      treeView1.ContextMenu.Show(treeView1, New Point(e.X, e.Y))
   End If
End Sub

Uwagi

Użyj menu skrótów, aby udostępnić użytkownikom opcje menu specyficzne dla kontekstu po kliknięciu kontrolki prawym przyciskiem myszy.

Uwagi dotyczące dziedziczenia

Podczas zastępowania ContextMenu właściwości w klasie pochodnej użyj właściwości klasy ContextMenu bazowej, aby rozszerzyć implementację podstawową. W przeciwnym razie należy podać całą implementację. Nie jest wymagane zastąpienie zarówno metod dostępuContextMenu, jak get i set właściwości ; w razie potrzeby można zastąpić tylko jedną.

Dotyczy

Zobacz też