Export (0) Print
Expand All

MenuItem.Index Property

Gets or sets a value indicating the position of the menu item in its parent menu.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public int Index { get; set; }
/** @property */
public int get_Index ()

/** @property */
public void set_Index (int value)

public function get Index () : int

public function set Index (value : int)

Property Value

The zero-based index representing the position of the menu item in its parent menu.

Exception typeCondition

ArgumentOutOfRangeException

The assigned value is less than zero or greater than the item count.

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. You can also use this property when creating a MenuItem to specify its position in a menu structure at the time of creation.

The following code example switches the position of two menu items in a menu. The following code example requires that two MenuItem objects are created named menuItem1 and 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.set_Index(menuItem1.get_Index() + 1);
    // Move menuItem2 up one position in the menu order.
    menuItem2.set_Index(menuItem2.get_Index() - 1);
} //SwitchMyMenuItems

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft