ContextMenu.Show 方法

定義

在指定位置顯示快捷鍵選單。

多載

名稱 Description
Show(Control, Point)

在指定位置顯示快捷鍵選單。

Show(Control, Point, LeftRightAlignment)

在指定位置及指定對齊位置顯示捷徑選單。

Show(Control, Point)

來源:
ContextMenu.cs
來源:
ContextMenu.cs

在指定位置顯示快捷鍵選單。

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

A Control 指定了這個捷徑選單所關聯的控制項。

pos
Point

A Point 指定顯示選單的座標。 這些座標相對於參數中 control 指定的控制項的客戶座標來指定。

例外狀況

參數 controlnull

控制鍵的握把不存在,或控制鍵不存在。

範例

以下程式碼範例示範如何建構捷徑選單並使用此 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控制項或區域的右滑鼠按鈕時,會顯示 aContextMenu。 你可以用這個方法手動在特定位置顯示捷徑選單,並綁定到特定的控制項。 此方法直到選單關閉後才會回歸。

適用於

Show(Control, Point, LeftRightAlignment)

來源:
ContextMenu.cs
來源:
ContextMenu.cs

在指定位置及指定對齊位置顯示捷徑選單。

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

A Control 指定了這個捷徑選單所關聯的控制項。

pos
Point

A Point 指定顯示選單的座標。 這些座標相對於參數中 control 指定的控制項的客戶座標來指定。

alignment
LeftRightAlignment

A LeftRightAlignment 指定控制項相對於 pos 參數的對齊。

適用於