共用方式為


ContextMenu 建構函式

定義

初始化 ContextMenu 類別的新執行個體。

多載

名稱 Description
ContextMenu()

初始化一個未指定選單項目的新類別實例 ContextMenu

ContextMenu(MenuItem[])

初始化一個新的類別實例 ContextMenu ,並以指定的物件集合 MenuItem

ContextMenu()

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

初始化一個未指定選單項目的新類別實例 ContextMenu

public:
 ContextMenu();
public ContextMenu();
Public Sub New ()

備註

使用完這個版本的建構子後,你可以用Add類別的方法Menu.MenuItemCollection將選單項目加入到選ContextMenu單中。 你可以透過物業MenuItems進入。Menu.MenuItemCollection

另請參閱

適用於

ContextMenu(MenuItem[])

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

初始化一個新的類別實例 ContextMenu ,並以指定的物件集合 MenuItem

public:
 ContextMenu(cli::array <System::Windows::Forms::MenuItem ^> ^ menuItems);
public ContextMenu(System.Windows.Forms.MenuItem[] menuItems);
new System.Windows.Forms.ContextMenu : System.Windows.Forms.MenuItem[] -> System.Windows.Forms.ContextMenu
Public Sub New (menuItems As MenuItem())

參數

menuItems
MenuItem[]

一組 MenuItem 物件,代表要加入快捷選單的選單項目。

範例

以下程式碼範例示範如何建構捷徑選單並使用此 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 一個,並在建立時指定了選單項目。 使用此版本建構子後,你可以利用Add類別的方法Menu.MenuItemCollection為 新增選單項目ContextMenu。 你可以透過物業MenuItems進入。Menu.MenuItemCollection

另請參閱

適用於