Well i've tried this:
private IEnumerable<ToolStripMenuItem> GetItems(ToolStripMenuItem item)
{
foreach (ToolStripMenuItem dropDownItem in item.DropDownItems)
{
if (dropDownItem.HasDropDownItems)
{
foreach (ToolStripMenuItem subItem in GetItems(dropDownItem))
yield return subItem;
}
yield return dropDownItem;
}
}
private void button2_Click_1(object sender, EventArgs e)
{
List<ToolStripMenuItem> allItems = new List<ToolStripMenuItem>();
foreach (ToolStripMenuItem toolItem in menuStrip1.Items)
{
allItems.Add(toolItem);
MessageBox.Show(toolItem.Text);
allItems.AddRange(GetItems(toolItem));
}
}
but i only get File
, Edit
, View
i need to reach Export
(see the figure) and its subitem
, and maybe change the visibility of Word
for example.
NOTE: the form
changes the menustrip
item dynamically thats why i need to loop through them.