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

備註

一般而言, 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

LeftRightAlignment,指定相對於 pos 參數的控制項之對齊方式。

適用於