MenuItem 构造函数

定义

初始化 MenuItem 类的新实例。Initializes a new instance of the MenuItem class.

重载

MenuItem()

使用空白标题初始化 MenuItemInitializes a MenuItem with a blank caption.

MenuItem(String)

使用菜单项的指定标题初始化 MenuItem 类的一个新实例。Initializes a new instance of the MenuItem class with a specified caption for the menu item.

MenuItem(String, EventHandler)

用指定标题和菜单项的 Click 事件的事件处理程序初始化该类的一个新实例。Initializes a new instance of the class with a specified caption and event handler for the Click event of the menu item.

MenuItem(String, MenuItem[])

用指定标题和为菜单项定义的一组子菜单项初始化该类的一个新实例。Initializes a new instance of the class with a specified caption and an array of submenu items defined for the menu item.

MenuItem(String, EventHandler, Shortcut)

用指定标题、事件处理程序和菜单项的关联快捷键初始化该类的一个新实例。Initializes a new instance of the class with a specified caption, event handler, and associated shortcut key for the menu item.

MenuItem(MenuMerge, Int32, Shortcut, String, EventHandler, EventHandler, EventHandler, MenuItem[])

用指定标题、为(MenuItemClickSelect)事件定义的事件处理程序、快捷键、合并类型和为菜单项指定的顺序来初始化 Popup 类的一个新实例。Initializes a new instance of the MenuItem class with a specified caption; defined event-handlers for the Click, Select and Popup events; a shortcut key; a merge type; and order specified for the menu item.

MenuItem()

使用空白标题初始化 MenuItemInitializes a MenuItem with a blank caption.

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

示例

下面的代码示例使用此版本的构造函数创建 MenuItemThe following code example creates a MenuItem using this version of the constructor.

public:
   void CreateMyMenu()
   {
      // Create an empty menu item object.
      MenuItem^ menuItem1 = gcnew MenuItem;
      // Intialize the menu item using the parameterless version of the constructor.
      // Set the caption of the menu item.
      menuItem1->Text = "&File";
   }
public void CreateMyMenu()
{
   // Create an empty menu item object.
   MenuItem menuItem1 = new MenuItem();
   // Intialize the menu item using the parameterless version of the constructor.
   // Set the caption of the menu item.
   menuItem1.Text = "&File";
}

Public Sub CreateMyMenu()
    ' Create an empty menu item object.
    Dim menuItem1 As New MenuItem()
    ' Intialize the menu item using the parameterless version of the constructor.
    ' Set the caption of the menu item.
    menuItem1.Text = "&File"
End Sub

注解

使用此构造函数创建空白 MenuItem 后,可以使用 MenuItem 类的属性和方法来指定 MenuItem的外观和行为。Once you have created a blank MenuItem using this constructor, you can use the properties and methods of the MenuItem class to specify the appearance and behavior of your MenuItem.

MenuItem(String)

使用菜单项的指定标题初始化 MenuItem 类的一个新实例。Initializes a new instance of the MenuItem class with a specified caption for the menu item.

public:
 MenuItem(System::String ^ text);
public MenuItem (string text);
new System.Windows.Forms.MenuItem : string -> System.Windows.Forms.MenuItem
Public Sub New (text As String)

参数

text
String

菜单项的标题。The caption for the menu item.

示例

下面的代码示例创建一个 MenuItem,它指定菜单项在构造时的标题。The following code example creates a MenuItem that specifies the caption of the menu item at the time it is constructed.

public:
   void CreateMyMenus()
   {
      // Create an instance of a MenuItem with a specified caption.
      menuItem1 = gcnew MenuItem( "&File" );
   }
public void CreateMyMenus()
{
   // Create an instance of a MenuItem with a specified caption.
   menuItem1 = new MenuItem("&File");
}

Public Sub CreateMyMenus()
    ' Create an instance of a MenuItem with a specified caption.
    menuItem1 = New MenuItem("&File")
End Sub

注解

使用 text 参数为菜单项指定标题时,还可以通过在要用作访问键的字符前放置 "&" 字符来指定访问密钥。When you specify a caption for your menu item with the text parameter, you can also specify an access key by placing an '&' character before the character to be used as the access key. 例如,若要在 "File" 中将 "F" 指定为访问键,请将菜单项的标题指定为 "& 文件"。For example, to specify the "F" in "File" as an access key, you would specify the caption for the menu item as "&File". 可以使用此功能为菜单提供键盘导航。You can use this feature to provide keyboard navigation for your menus.

text 参数设置为 "-" 会导致菜单项显示为分隔符(水平线)而不是标准菜单项。Setting the text parameter to "-" causes your menu item to be displayed as a separator (a horizontal line) rather than a standard menu item.

MenuItem(String, EventHandler)

用指定标题和菜单项的 Click 事件的事件处理程序初始化该类的一个新实例。Initializes a new instance of the class with a specified caption and event handler for the Click event of the menu item.

public:
 MenuItem(System::String ^ text, EventHandler ^ onClick);
public MenuItem (string text, EventHandler onClick);
new System.Windows.Forms.MenuItem : string * EventHandler -> System.Windows.Forms.MenuItem
Public Sub New (text As String, onClick As EventHandler)

参数

text
String

菜单项的标题。The caption for the menu item.

onClick
EventHandler

处理该菜单项的 EventHandler 事件的 ClickThe EventHandler that handles the Click event for this menu item.

示例

下面的代码示例创建一个 MenuItem 对象,该对象具有指定的标题和一个连接到将处理菜单项的 Click 事件的事件处理程序的 EventHandler 委托。The following code example creates a MenuItem object with a specified caption and an EventHandler delegate connected to an event handler that will handle the Click event for the menu item.

public:
   void CreateMyMenuItem()
   {
      // Create an instance of MenuItem with caption and an event handler
      MenuItem^ menuItem1 = gcnew MenuItem( "&New",gcnew System::EventHandler(
         this, &Form1::MenuItem1_Click ) );
   }

private:
   // This method is an event handler for menuItem1 to use when connecting its event handler.
   void MenuItem1_Click( Object^ sender, System::EventArgs^ e )
   {
      // Code goes here that handles the Click event.
   }
public void CreateMyMenuItem()
{
   // Create an instance of MenuItem with caption and an event handler
   MenuItem menuItem1 = new MenuItem("&New", new System.EventHandler(this.MenuItem1_Click));
}

// This method is an event handler for menuItem1 to use when connecting its event handler.
private void MenuItem1_Click(Object sender, System.EventArgs e) 
{
   // Code goes here that handles the Click event.
}
  
Public Sub CreateMyMenuItem()
    ' Create an instance of MenuItem with caption and an event 
    ' handler
    Dim MenuItem1 As New MenuItem("&New", New _
        System.EventHandler(AddressOf Me.MenuItem1_Click))
End Sub
' This method is an event handler for MenuItem1 to use when 
' connecting its event handler.
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal _
    e as System.EventArgs)
    ' Code goes here that handles the Click event.
End Sub
  

注解

使用 text 参数为菜单项指定标题时,还可以通过在用作访问键的字符前放置 "&" 来指定访问密钥。When you specify a caption for your menu item with the text parameter, you can also specify an access key by placing an '&' before the character to be used as the access key. 例如,若要在 "File" 中将 "F" 指定为访问键,请将菜单项的标题指定为 "& 文件"。For example, to specify the "F" in "File" as an access key, you would specify the caption for the menu item as "&File". 可以使用此功能为菜单提供键盘导航。You can use this feature to provide keyboard navigation for your menus.

text 参数设置为 "-" 会导致菜单项显示为分隔符(水平线)而不是标准菜单项。Setting the text parameter to "-" causes your menu item to be displayed as a separator (a horizontal line) rather than a standard menu item.

此外,还可以使用此构造函数指定一个委托,该委托将处理所创建菜单项的 Click 事件。In addition, you can use this constructor to specify a delegate that will handle the Click event for the menu item being created. 传递给此构造函数的 EventHandler 必须配置为调用可处理 Click 事件的事件处理程序。The EventHandler that you pass to this constructor must be configured to call an event handler that can handle the Click event. 有关处理事件的详细信息,请参阅处理和引发事件For more information on handling events, see Handling and Raising Events.

MenuItem(String, MenuItem[])

用指定标题和为菜单项定义的一组子菜单项初始化该类的一个新实例。Initializes a new instance of the class with a specified caption and an array of submenu items defined for the menu item.

public:
 MenuItem(System::String ^ text, cli::array <System::Windows::Forms::MenuItem ^> ^ items);
public MenuItem (string text, System.Windows.Forms.MenuItem[] items);
new System.Windows.Forms.MenuItem : string * System.Windows.Forms.MenuItem[] -> System.Windows.Forms.MenuItem
Public Sub New (text As String, items As MenuItem())

参数

text
String

菜单项的标题。The caption for the menu item.

items
MenuItem[]

包含该菜单项的子菜单项的一组 MenuItem 对象。An array of MenuItem objects that contains the submenu items for this menu item.

示例

下面的代码示例创建一个具有指定标题的对象,该事件处理程序连接到将处理子菜单项数组中的每个菜单项的事件的方法。The following code example creates an object with a specified caption, an event handler connected to a method that will handle the event each menu item in an array of submenu items.

public:
   void CreateMyMenuItem()
   {
      // submenu item array.
      array<MenuItem^>^ subMenus = gcnew array<MenuItem^>(3);
      // Create three menu items to add to the submenu item array.
      MenuItem^ subMenuItem1 = gcnew MenuItem( "Red" );
      MenuItem^ subMenuItem2 = gcnew MenuItem( "Blue" );
      MenuItem^ subMenuItem3 = gcnew MenuItem( "Green" );
      // Add the submenu items to the array.
      subMenus[ 0 ] = subMenuItem1;
      subMenus[ 1 ] = subMenuItem2;
      subMenus[ 2 ] = subMenuItem3;
      // Create an instance of a MenuItem with caption and an array of submenu
      // items specified.
      MenuItem^ MenuItem1 = gcnew MenuItem( "&Colors",subMenus );
   }
public void CreateMyMenuItem()
{
   // submenu item array.
   MenuItem[] subMenus = new MenuItem[3];
   // Create three menu items to add to the submenu item array.
   MenuItem subMenuItem1 = new MenuItem("Red");
   MenuItem subMenuItem2 = new MenuItem("Blue");
   MenuItem subMenuItem3 = new MenuItem("Green");
   // Add the submenu items to the array.
   subMenus[0] = subMenuItem1;
   subMenus[1] = subMenuItem2;
   subMenus[2] = subMenuItem3;
   // Create an instance of a MenuItem with caption and an array of submenu
   // items specified.
   MenuItem MenuItem1 = new MenuItem("&Colors", subMenus);
}
  
Public Sub CreateMyMenuItem()
    ' submenu item array.
    Dim subMenus(3) As MenuItem
    ' Create three menu items to add to the submenu item array.
    Dim subMenuItem1 As New MenuItem("Red")
    Dim subMenuItem2 As New MenuItem("Blue")
    Dim subMenuItem3 As New MenuItem("Green")
    ' Add the submenu items to the array.
    subMenus(0) = subMenuItem1
    subMenus(1) = subMenuItem2
    subMenus(2) = subMenuItem3
    ' Create an instance of a MenuItem with caption and an array of submenu
    ' items specified.
    Dim MenuItem1 As New MenuItem("&Colors", subMenus)
End Sub

注解

使用 text 参数为菜单项指定标题时,还可以通过在用作访问键的字符前放置 "&" 来指定访问密钥。When you specify a caption for your menu item with the text parameter, you can also specify an access key by placing an '&' before the character to be used as the access key. 例如,若要在 "File" 中将 "F" 指定为访问键,请将菜单项的标题指定为 "& 文件"。For example, to specify the "F" in "File" as an access key, you would specify the caption for the menu item as "&File". 可以使用此功能为菜单提供键盘导航。You can use this feature to provide keyboard navigation for your menus.

text 参数设置为 "-" 会导致菜单项显示为分隔符(水平线)而不是标准菜单项。Setting the text parameter to "-" causes your menu item to be displayed as a separator (a horizontal line) rather than a standard menu item.

使用 items 参数可以分配一组菜单项来定义此菜单项的子菜单。The items parameter enables you to assign an array of menu items to define a submenu of this menu item. 数组中的每一项还可以有一个分配给它的菜单项的数组。Each item in the array can also have an array of menu items assigned to it. 这使您可以创建完整的菜单结构,并将其分配给菜单项的构造函数。This enables you to create complete menu structures and assign them to the constructor for the menu item.

有关处理事件的详细信息,请参阅处理和引发事件For more information on handling events, see Handling and Raising Events.

MenuItem(String, EventHandler, Shortcut)

用指定标题、事件处理程序和菜单项的关联快捷键初始化该类的一个新实例。Initializes a new instance of the class with a specified caption, event handler, and associated shortcut key for the menu item.

public:
 MenuItem(System::String ^ text, EventHandler ^ onClick, System::Windows::Forms::Shortcut shortcut);
public MenuItem (string text, EventHandler onClick, System.Windows.Forms.Shortcut shortcut);
new System.Windows.Forms.MenuItem : string * EventHandler * System.Windows.Forms.Shortcut -> System.Windows.Forms.MenuItem

参数

text
String

菜单项的标题。The caption for the menu item.

onClick
EventHandler

处理该菜单项的 EventHandler 事件的 ClickThe EventHandler that handles the Click event for this menu item.

shortcut
Shortcut

Shortcut 值之一。One of the Shortcut values.

示例

下面的代码示例创建一个对象,该对象具有指定的标题、快捷键和一个连接到将处理菜单项的事件的方法的事件处理程序。The following code example creates an object with a specified caption, shortcut key, and an event handler connected to a method that will handle the event for the menu item.

public:
   void CreateMyMenuItem()
   {
      // Create a MenuItem with caption, shortcut key, and an event handler
      // specified.
      MenuItem^ MenuItem1 = gcnew MenuItem( "&New",
         gcnew System::EventHandler( this, &Form1::MenuItem1_Click ), Shortcut::CtrlL );
   }

private:
   // The following method is an event handler for menuItem1 to use when
   // connecting the event handler.
   void MenuItem1_Click( Object^ sender, EventArgs^ e )
   {
      // Code goes here that handles the Click event.
   }
public void CreateMyMenuItem()
{
   // Create a MenuItem with caption, shortcut key, and an event handler
   // specified.
   MenuItem MenuItem1 = new MenuItem("&New",
       new System.EventHandler(this.MenuItem1_Click), Shortcut.CtrlL);
}

// The following method is an event handler for menuItem1 to use when
// connecting the event handler.
private void MenuItem1_Click(Object sender, EventArgs e)
{
   // Code goes here that handles the Click event.
}
  
Public Sub CreateMyMenuItem()
    ' Create a MenuItem with caption, shortcut key, and an event handler
    ' specified.
    Dim MenuItem1 As New MenuItem("&New", _
       New System.EventHandler(AddressOf Me.MenuItem1_Click), Shortcut.CtrlL)
End Sub    
   
' The following method is an event handler for menuItem1 to use when
' connecting the event handler.
Private Sub MenuItem1_Click(sender As Object, e As EventArgs)
    ' Code goes here that handles the Click event.
End Sub

注解

使用 text 参数为菜单项指定标题时,还可以通过在用作访问键的字符前放置 "&" 来指定访问密钥。When you specify a caption for your menu item with the text parameter, you can also specify an access key by placing an '&' before the character to be used as the access key. 例如,若要在 "File" 中将 "F" 指定为访问键,请将菜单项的标题指定为 "& 文件"。For example, to specify the "F" in "File" as an access key, you would specify the caption for the menu item as "&File". 可以使用此功能为菜单提供键盘导航。You can use this feature to provide keyboard navigation for your menus. 使用此构造函数还可以指定快捷键,以及访问密钥来提供键盘导航。This constructor also enables you to specify a shortcut key in addition to an access key to provide keyboard navigation. 快捷键允许您指定可用于激活菜单项的键的组合。Shortcut keys allow you to specify a combination of keys that can be used to activate the menu item.

text 参数设置为 "-" 会导致菜单项显示为分隔符(水平线)而不是标准菜单项。Setting the text parameter to "-" causes your menu item to be displayed as a separator (a horizontal line) rather than a standard menu item.

此外,还可以使用此构造函数指定一个委托,该委托将处理所创建菜单项的 Click 事件。In addition, you can use this constructor to specify a delegate that will handle the Click event for the menu item being created. 传递给此构造函数的 EventHandler 必须配置为调用可处理 Click 事件的事件处理程序。The EventHandler that you pass to this constructor must be configured to call an event handler that can handle the Click event. 有关处理事件的详细信息,请参阅处理和引发事件For more information on handling events, see Handling and Raising Events.

MenuItem(MenuMerge, Int32, Shortcut, String, EventHandler, EventHandler, EventHandler, MenuItem[])

用指定标题、为(MenuItemClickSelect)事件定义的事件处理程序、快捷键、合并类型和为菜单项指定的顺序来初始化 Popup 类的一个新实例。Initializes a new instance of the MenuItem class with a specified caption; defined event-handlers for the Click, Select and Popup events; a shortcut key; a merge type; and order specified for the menu item.

public:
 MenuItem(System::Windows::Forms::MenuMerge mergeType, int mergeOrder, System::Windows::Forms::Shortcut shortcut, System::String ^ text, EventHandler ^ onClick, EventHandler ^ onPopup, EventHandler ^ onSelect, cli::array <System::Windows::Forms::MenuItem ^> ^ items);
public MenuItem (System.Windows.Forms.MenuMerge mergeType, int mergeOrder, System.Windows.Forms.Shortcut shortcut, string text, EventHandler onClick, EventHandler onPopup, EventHandler onSelect, System.Windows.Forms.MenuItem[] items);
new System.Windows.Forms.MenuItem : System.Windows.Forms.MenuMerge * int * System.Windows.Forms.Shortcut * string * EventHandler * EventHandler * EventHandler * System.Windows.Forms.MenuItem[] -> System.Windows.Forms.MenuItem

参数

mergeType
MenuMerge

MenuMerge 值之一。One of the MenuMerge values.

mergeOrder
Int32

此菜单项在合并菜单中将占有的相对位置。The relative position that this menu item will take in a merged menu.

shortcut
Shortcut

Shortcut 值之一。One of the Shortcut values.

text
String

菜单项的标题。The caption for the menu item.

onClick
EventHandler

处理该菜单项的 EventHandler 事件的 ClickThe EventHandler that handles the Click event for this menu item.

onPopup
EventHandler

处理该菜单项的 EventHandler 事件的 PopupThe EventHandler that handles the Popup event for this menu item.

onSelect
EventHandler

处理该菜单项的 EventHandler 事件的 SelectThe EventHandler that handles the Select event for this menu item.

items
MenuItem[]

包含该菜单项的子菜单项的一组 MenuItem 对象。An array of MenuItem objects that contains the submenu items for this menu item.

示例

下面的代码示例创建一个具有标题和快捷键的菜单项。The following code example creates a menu item that has a caption and shortcut key. 菜单项还具有为 PopupClickSelect 事件定义的事件处理程序。The menu item also has event handlers defined for the Popup, Click, and Select events. 如果此菜单项已合并,它会将菜单项添加到合并顺序为零的菜单。If this menu item is merged, it will add the menu item to the menu with the merge order of zero.

public:
   void CreateMyMenuItem()
   {
      // Submenu item array.
      array<MenuItem^>^ subMenus = gcnew array<MenuItem^>(3);
      // Create three menu items to add to the submenu item array.
      MenuItem^ subMenuItem1 = gcnew MenuItem( "Red" );
      MenuItem^ subMenuItem2 = gcnew MenuItem( "Blue" );
      MenuItem^ subMenuItem3 = gcnew MenuItem( "Green" );
      
      // Add the submenu items to the array.
      subMenus[ 0 ] = subMenuItem1;
      subMenus[ 1 ] = subMenuItem2;
      subMenus[ 2 ] = subMenuItem3;
      /* Create a MenuItem with caption, shortcut key, 
         a Click, Popup, and Select event handler, merge type and order, and an 
         array of submenu items specified.
      */
      MenuItem^ menuItem1 = gcnew MenuItem( MenuMerge::Add, 0,
         Shortcut::CtrlShiftC, "&Colors",
         gcnew EventHandler( this, &Form1::MenuItem1_Click ),
         gcnew EventHandler( this, &Form1::MenuItem1_Popup ),
         gcnew EventHandler( this, &Form1::MenuItem1_Select ), subMenus );
   }

private:
   // The following method is an event handler for menuItem1 to use when connecting the Click event.
   void MenuItem1_Click( Object^ sender, EventArgs^ e )
   {
      // Code goes here that handles the Click event.
   }

   // The following method is an event handler for menuItem1 to use  when connecting the Popup event.
   void MenuItem1_Popup( Object^ sender, EventArgs^ e )
   {
      // Code goes here that handles the Click event.
   }

   // The following method is an event handler for menuItem1 to use  when connecting the Select event
   void MenuItem1_Select( Object^ sender, EventArgs^ e )
   {
      // Code goes here that handles the Click event.
   }
public void CreateMyMenuItem()
{
   // Submenu item array.
   MenuItem[] subMenus = new MenuItem[3];
   // Create three menu items to add to the submenu item array.
   MenuItem subMenuItem1 = new MenuItem("Red");
   MenuItem subMenuItem2 = new MenuItem("Blue");
   MenuItem subMenuItem3 = new MenuItem("Green");

   // Add the submenu items to the array.
   subMenus[0] = subMenuItem1;
   subMenus[1] = subMenuItem2;
   subMenus[2] = subMenuItem3;
   /* Create a MenuItem with caption, shortcut key, 
      a Click, Popup, and Select event handler, merge type and order, and an 
      array of submenu items specified.
   */
   MenuItem menuItem1 = new MenuItem(MenuMerge.Add, 0,
      Shortcut.CtrlShiftC, "&Colors", 
      new EventHandler(this.MenuItem1_Click),
      new EventHandler(this.MenuItem1_Popup),
      new EventHandler(this.MenuItem1_Select), subMenus);
}

// The following method is an event handler for menuItem1 to use when connecting the Click event.
private void MenuItem1_Click(Object sender, EventArgs e)
{
   // Code goes here that handles the Click event.
}

// The following method is an event handler for menuItem1 to use  when connecting the Popup event.
private void MenuItem1_Popup(Object sender, EventArgs e)
{
   // Code goes here that handles the Click event.
}

// The following method is an event handler for menuItem1 to use  when connecting the Select event
private void MenuItem1_Select(Object sender, EventArgs e)
{
   // Code goes here that handles the Click event.
}

Public Sub CreateMyMenuItem()
   ' Submenu item array.
   Dim SubMenus(3) as MenuItem
   ' Create three menu items to add to the submenu item array.
   Dim SubMenuItem1, SubMenuItem2, SubMenuItem3 as MenuItem
   SubMenuItem1 = New MenuItem ("Red")
   SubMenuItem2 = New MenuItem ("Blue")
   SubMenuItem3 = New MenuItem ("Green")
   ' Add the submenu items to the array.
   SubMenus(0) = SubMenuItem1
   SubMenus(1) = SubMenuItem2
   SubMenus(2) = SubMenuItem3
   ' Create a MenuItem with caption, shortcut key, 
   ' a Click, Popup, and Select event handler, menu merge type and order, and an 
   ' array of submenu items specified.
   Dim MenuItem1 As MenuItem
   MenuItem1 = New MenuItem(MenuMerge.Add, 0, Shortcut.CtrlShiftC, "&Colors", _
      AddressOf Me.MenuItem1_Click, _
      AddressOf Me.MenuItem1_Popup, _
      AddressOf Me.MenuItem1_Select, SubMenus)
End Sub

' The following method is an event handler for MenuItem1 to use  when connecting the Click event.
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal  e as System.EventArgs)
   ' Code goes here that handles the Click event.
End Sub

' The following method is an event handler for MenuItem1 to use  when connecting the Popup event.
Private Sub MenuItem1_Popup(ByVal sender As System.Object, ByVal  e as System.EventArgs)
   ' Code goes here that handles the Click event.
End Sub

' The following method is an event handler for MenuItem1 to use  when connecting the Select event
Private Sub MenuItem1_Select(ByVal sender As System.Object, ByVal  e as System.EventArgs)
   ' Code goes here that handles the Click event.
End Sub

注解

使用 text 参数为菜单项指定标题时,还可以通过在用作访问键的字符前放置 "&" 来指定访问密钥。When you specify a caption for your menu item with the text parameter, you can also specify an access key by placing an '&' before the character to be used as the access key. 例如,若要在 "File" 中将 "F" 指定为访问键,请将菜单项的标题指定为 "& 文件"。For example, to specify the "F" in "File" as an access key, you would specify the caption for the menu item as "&File". 可以使用此功能为菜单提供键盘导航。You can use this feature to provide keyboard navigation for your menus.

text 参数设置为 "-" 会导致菜单项显示为分隔符(水平线)而不是标准菜单项。Setting the text parameter to "-" causes your menu item to be displayed as a separator (a horizontal line) rather than a standard menu item.

使用 items 参数可以分配一组菜单项来定义此菜单项的子菜单。The items parameter enables you to assign an array of menu items to define a submenu of this menu item. 数组中的每一项还可以有一个分配给它的菜单项的数组。Each item in the array can also have an array of menu items assigned to it. 这使您可以创建完整的菜单结构,并将其分配给菜单项的构造函数。This enables you to create complete menu structures and assign them to the constructor for the menu item.

mergeTypemergeOrder 参数可用于确定当菜单项与另一个菜单合并时该菜单项的行为方式。The mergeType and mergeOrder parameters allow you to determine how this menu item will behave when the menu item is merged with another menu. 根据为 mergeType 参数指定的值,可以添加、移除、替换菜单项及其子菜单项,也可以将其与要合并的菜单一起添加。Depending on the value you specify for the mergeType parameter, you can either add, remove, replace, or merge the menu item and its submenu items with the menu that it is merging with. mergeOrder 参数确定当菜单合并时要创建的菜单项的位置。The mergeOrder parameter determines where the menu item being created will be positioned when the menu is merged.

此外,还可以使用此构造函数创建 MenuItem,并将其连接到代码中将处理菜单项单击操作的事件处理程序。In addition, you can use this constructor to create a MenuItem and have it connected to an event handler in your code that will process the click of the menu item. 传递到此构造函数的 EventHandler 应配置为调用可处理 Click 事件的事件处理程序。The EventHandler that you pass into this constructor should be configured to call an event handler that can handle the Click event. 使用此构造函数版本,还可以连接 PopupSelect 事件以确定此菜单项的选择时间。By using this constructor version, you can also connect the Popup and Select events to determine when this menu item is selected. 您可以使用这些事件来执行任务,例如确定是否在子菜单项旁显示复选标记,或启用或禁用基于应用程序状态的菜单项。You can use these events for tasks such as determining whether or not to display a check mark next to submenu items or to enable or disable menu items based on the state of the application. 仅对非父菜单项的 MenuItem 对象引发 SelectClick 事件。The Select and Click events are raised only for MenuItem objects that are not parent menu items. 有关处理事件的详细信息,请参阅处理和引发事件For more information on handling events, see Handling and Raising Events.

另请参阅

适用于