Kairan
Kairan

Reputation: 5542

c# menustrip key value

I was watching a tutorial video on the MenuStrip control for WindowsForms and the video provided by MSDN site indicates you could reference a specific menu item using a "key" rather than an index number - but they never explained how and a quick search yielded me with no results.

How can you reference a menu item by its name rather than an index number (which can change if you add new menu items) ?

Upvotes: 1

Views: 532

Answers (1)

Khan
Khan

Reputation: 18162

It is the same way as the index. Just provide a string representing the name of the menu item instead of the known index of the item. This is known as the key value.

index Example:

    var fileMenuItem = menuStrip1.Items[0];

string Example:

    var fileMenuItem = menuStrip1.Items["File"];

Upvotes: 2

Related Questions