Control.ContextMenu 属性

定义

获取或设置与控件关联的快捷菜单。

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

属性值

ContextMenu

一个 ContextMenu,表示与控件关联的快捷菜单。

属性

示例

下面的代码示例显示 ContextMenu 单击并释放鼠标右键时分配给 a TreeView 的代码示例。 此代码要求你具有 Form 其上的代码 TreeView 。 此外TreeView,还需要为其属性分配ContextMenu一个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

注解

右键单击控件时,使用快捷菜单向用户提供特定于上下文的菜单选项。

继承者说明

重写 ContextMenu 派生类中的属性时,请使用基类的属性 ContextMenu 扩展基实现。 否则,必须提供所有实现。 无需同时替代 get 属性和 set 访问器 ContextMenu ;仅可根据需要重写一个。

适用于

另请参阅