Bagikan melalui


Control.ContextMenu Properti

Definisi

Perhatian

ContextMenu is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use ContextMenuStrip instead.

Mendapatkan atau mengatur menu pintasan yang terkait dengan kontrol.

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; }
[System.ComponentModel.Browsable(false)]
[System.Obsolete("`ContextMenu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ContextMenuStrip` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
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
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("`ContextMenu` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `ContextMenuStrip` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
member this.ContextMenu : System.Windows.Forms.ContextMenu with get, set
Public Overridable Property ContextMenu As ContextMenu

Nilai Properti

ContextMenu yang mewakili menu pintasan yang terkait dengan kontrol.

Atribut

Contoh

Contoh kode berikut menampilkan yang ContextMenu ditetapkan ke TreeView saat tombol kanan mouse diklik dan dilepaskan. Kode ini mengharuskan Anda memiliki Form dengan TreeView di atasnya. Diperlukan juga bahwa TreeView memiliki yang ContextMenu ditetapkan ke propertinya 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

Keterangan

Gunakan menu pintasan untuk memberikan opsi menu khusus konteks kepada pengguna saat mereka mengklik kanan kontrol.

Catatan Bagi Inheritor

Saat mengambil alih ContextMenu properti di kelas turunan, gunakan properti kelas ContextMenu dasar untuk memperluas implementasi dasar. Jika tidak, Anda harus menyediakan semua implementasi. Anda tidak diharuskan untuk mengambil alih properti get dan set aksesor ContextMenu ; Anda hanya dapat mengambil alih satu jika diperlukan.

Berlaku untuk

Lihat juga