Ranorex

Do you have C# sample code on how to enumerate Menu Items?

 
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexNet
View previous topic :: View next topic  
Author Message
kosorok



Joined: 07 Sep 2006
Posts: 1

PostPosted: Thu Sep 07, 2006 3:54 am    Post subject: 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...
Back to top
View user's profile Send private message MSN Messenger
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Thu Sep 07, 2006 8:48 pm    Post subject:
The following code sample dumps out all submenus and all submenu items of a menu bar.

Code: click into code to enlarge
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);
    }
}

You can select a menu item as follows:

Code: click into code to enlarge
// 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");

Jenö Herget
Ranorex Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexNet All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum