ContextMenu.Show メソッド

定義

指定した位置にショートカット メニューを表示します。

オーバーロード

Show(Control, Point)

指定した位置にショートカット メニューを表示します。

Show(Control, Point, LeftRightAlignment)

位置および配置を指定してショートカット メニューを表示します。

Show(Control, Point)

指定した位置にショートカット メニューを表示します。

public:
 void Show(System::Windows::Forms::Control ^ control, System::Drawing::Point pos);
public void Show (System.Windows.Forms.Control control, System.Drawing.Point pos);
member this.Show : System.Windows.Forms.Control * System.Drawing.Point -> unit
Public Sub Show (control As Control, pos As Point)

パラメーター

control
Control

ショートカット メニューが関連付けられたコントロールを指定する Control

pos
Point

メニューを表示する座標を指定する Point。 座標は、control パラメーターで指定したコントロールのクライアント座標に対して相対的に指定されます。

例外

control パラメーターが null です。

コントロールのハンドルが存在しないか、コントロールが表示されていません。

次のコード例は、ショートカット メニューを作成し、メソッドを使用する方法を Show 示しています。 この例を実行するには、Button1 という名前のボタンを含むフォームに次のコードを貼り付けます。 すべてのイベントがイベント処理メソッドに関連付けられていることを確認します。

// Displays the shortcut menu, offsetting its location 
// from the upper-left corner of Button1 by 20 pixels in each direction. 
void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   
   //Declare the menu items and the shortcut menu.
   array<MenuItem^>^menuItems = {gcnew MenuItem( "Some Button Info" ),gcnew MenuItem( "Some Other Button Info" ),gcnew MenuItem( "Exit" )};
   System::Windows::Forms::ContextMenu^ buttonMenu = gcnew System::Windows::Forms::ContextMenu( menuItems );
   buttonMenu->Show( Button1, System::Drawing::Point( 20, 20 ) );
}

// Displays the shortcut menu, offsetting its location 
// from the upper-left corner of Button1 by 20 pixels in each direction. 
private void Button1_Click(System.Object sender, System.EventArgs e)
{

    //Declare the menu items and the shortcut menu.
    MenuItem[] menuItems = new MenuItem[]{new MenuItem("Some Button Info"), 
        new MenuItem("Some Other Button Info"), new MenuItem("Exit")};

    ContextMenu buttonMenu = new ContextMenu(menuItems);
    buttonMenu.Show(Button1, new System.Drawing.Point(20, 20));
}

' Displays the shortcut menu, offsetting its location 
' from the upper-left corner of Button1 by 20 pixels in each direction. 
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    'Declare the menu items and the shortcut menu.
    Dim menuItems() As MenuItem = New MenuItem() _
        {New MenuItem("Some Button Info"), _
        New MenuItem("Some Other Button Info"), _
        New MenuItem("Exit")}

    Dim buttonMenu As New ContextMenu(menuItems)
    buttonMenu.Show(Button1, New System.Drawing.Point(20, 20))
End Sub

注釈

通常、a ContextMenu は、ユーザーがバインドされているフォーム ContextMenu のコントロールまたは領域でマウスの右ボタンをクリックしたときに表示されます。 このメソッドを使用すると、ショートカット メニューを特定の場所に手動で表示し、特定のコントロールにバインドできます。 このメソッドは、メニューが閉じるまで戻りません。

適用対象

Show(Control, Point, LeftRightAlignment)

位置および配置を指定してショートカット メニューを表示します。

public:
 void Show(System::Windows::Forms::Control ^ control, System::Drawing::Point pos, System::Windows::Forms::LeftRightAlignment alignment);
public void Show (System.Windows.Forms.Control control, System.Drawing.Point pos, System.Windows.Forms.LeftRightAlignment alignment);
member this.Show : System.Windows.Forms.Control * System.Drawing.Point * System.Windows.Forms.LeftRightAlignment -> unit
Public Sub Show (control As Control, pos As Point, alignment As LeftRightAlignment)

パラメーター

control
Control

ショートカット メニューが関連付けられたコントロールを指定する Control

pos
Point

メニューを表示する座標を指定する Point。 座標は、control パラメーターで指定したコントロールのクライアント座標に対して相対的に指定されます。

alignment
LeftRightAlignment

コントロールの配置を pos パラメーターを基準に相対的に指定する LeftRightAlignment

適用対象