MenuItem.Index 属性

定义

获取或设置一个值,通过该值指示菜单项在其父菜单中的位置。Gets or sets a value indicating the position of the menu item in its parent menu.

public:
 property int Index { int get(); void set(int value); };
[System.ComponentModel.Browsable(false)]
public int Index { get; set; }
member this.Index : int with get, set
Public Property Index As Integer

属性值

表示菜单项在其父菜单中位置的从零开始的索引。The zero-based index representing the position of the menu item in its parent menu.

属性

异常

赋值小于零或大于项的数目。The assigned value is less than zero or greater than the item count.

示例

下面的代码示例在菜单中切换两个菜单项的位置。The following code example switches the position of two menu items in a menu. 下面的代码示例要求创建两个名为 menuItem1menuItem2MenuItem 对象。The following code example requires that two MenuItem objects are created named menuItem1 and menuItem2. menuItem1 菜单项在菜单中向下移动一个位置,而 menuItem2 会向上移动一个位置。The menuItem1 menu item moves down one position in the menu, while menuItem2 moves up one position.

public:
   void SwitchMyMenuItems()
   {
      // Move menuItem1 down one position in the menu order.
      menuItem1->Index = menuItem1->Index + 1;
      // Move menuItem2 up one position in the menu order.
      menuItem2->Index = menuItem2->Index - 1;
   }
public void SwitchMyMenuItems()
{
   // Move menuItem1 down one position in the menu order.
   menuItem1.Index = menuItem1.Index + 1;
   // Move menuItem2 up one position in the menu order.
   menuItem2.Index = menuItem2.Index - 1;
}

Public Sub SwitchMyMenuItems()
    ' Move menuItem1 down one position in the menu order.
    menuItem1.Index = menuItem1.Index + 1
    ' Move menuItem2 up one position in the menu order.
    menuItem2.Index = menuItem2.Index - 1
End Sub

注解

此属性提供菜单项在其父菜单的菜单项集合中的索引位置。This property provides the indexed position of a menu item in the menu item collection of its parent menu. 您可以使用此属性将菜单项重新定位到其菜单中的不同位置。You can use this property to reposition a menu item to a different location within its menu. 在创建 MenuItem 时,还可以使用此属性来指定其在菜单结构中的位置。You can also use this property when creating a MenuItem to specify its position in a menu structure at the time of creation.

适用于