Control.ContextMenu 属性  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置与控件关联的快捷菜单。
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, setPublic Overridable Property ContextMenu As 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 ;仅可根据需要重写一个。