Do you have C# sample code on how to enumerate Menu Items?
Do you have C# sample code on how to enumerate Menu Items?
I've been able to find the MenuBar item in our application, but I'd like to see if you have any C# sample code on how to enumerate through the object to get all the available menu items, then be able to click on the desired menu item. For example, I can find the menu bar with File | Help on it, then I'd like to be able to select Help | About, or File | Open...
The following code sample dumps out all submenus and all submenu items of a menu bar.
You can select a menu item as follows:
Jenö Herget
Ranorex Team
Code: Select all
Int32 submenuCount = menuStrip.GetItemCount();
for (int position = 1; position <= submenuCount; position++)
{
String submenuText = menuStrip.GetItemText(position);
Console.WriteLine(" Submenu({0})={1}", position, submenuText);
Int32 itemCount = menuStrip.GetItemCount(position);
for (int itemPosition = 1; itemPosition <= itemCount; itemPosition++)
{
itemText = menuStrip.GetItemText(position,itemPosition);
Console.WriteLine(" Item({0})={1}", itemPosition, itemText);
}
}
Code: Select all
// Select the third menu item of the first submenu
menuStrip.SelectPosition(1,3);
// Select the Open menu item of the File submenu
menuStrip.SelectItemText("File","Open");
Ranorex Team