Control.ContextMenu プロパティ

定義

注意事項

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

コントロールに関連付けられているショートカット メニューを取得または設定します。

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

プロパティ値

コントロールに関連付けられているショートカット メニューを表す ContextMenu

属性

次のコード例では、マウスの右ボタンをクリックして離したときに、TreeViewに割り当てられたContextMenuを表示します。 このコードでは、TreeViewを含むFormが必要です。 また、TreeViewContextMenu プロパティに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 プロパティを使用して基本実装を拡張します。 それ以外の場合は、すべての実装を指定する必要があります。 ContextMenu プロパティのgetアクセサーと set アクセサーの両方をオーバーライドする必要はありません。必要に応じて 1 つだけオーバーライドできます。

適用対象

こちらもご覧ください