MenuItem.Index Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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; }
[<System.ComponentModel.Browsable(false)>]
member this.Index : int with get, set
Public Property Index As Integer
Property Value
The zero-based index representing the position of the menu item in its parent menu.
- Attributes
Exceptions
The assigned value is less than zero or greater than the item count.
Examples
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.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
Remarks
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.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기