getting menu items

  • Thread starter Thread starter Adam Right
  • Start date Start date
A

Adam Right

is it possible to get the all MenuStrip, ToolStrip and all sub menu items,
without using reflection?
 
Probably - assuming that they are linked to your form:

MenuStrip menu = form.MainMenuStrip;
if (menu != null) {
WalkItems(menu.Items);
}
...
static void WalkItems(ToolStripItemCollection items) {
foreach (ToolStripItem item in items) {
// do something with this item
Console.WriteLine(item.ToString());

// enumerate sub-items (if could have them)
ToolStripDropDownItem dropItem = item as
ToolStripDropDownItem;
if (dropItem != null) {
WalkItems(dropItem.DropDownItems);
}
}
}

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top