如何计算菜单条和子菜单中的值。 [英] How to count value in menu strip and submenustrip.
本文介绍了如何计算菜单条和子菜单中的值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void itemcount()
{
//for (int i = 0; i < this.menuStrip.Items.Count; i++)
//{
// //main menus items
// string mnuItemName = this.menuStrip.Items[i].Name;
// ToolStripMenuItem tmpMenuItem = this.menuStrip.Items[i] as ToolStripMenuItem;
// //check for sub menu
// for (int j = 0; j < tmpMenuItem.DropDownItems.Count; j++)
// {
// string menuSubItem = tmpMenuItem.DropDownItems[j].Name;
// MessageBox.Show(menuSubItem);
// }
//}
foreach (ToolStripMenuItem masterToolStripMenuItem in this.menuStrip.Items)
{
foreach (ToolStripMenuItem master in this.masterToolStripMenuItem.DropDownItems)
{//mnu.Text = main item
//You can just count:
int @int = masterToolStripMenuItem.DropDownItems.Count;
MessageBox.Show(@int.ToString());
break;
//Or Loop perhaps to get even more if needed
//foreach (ToolStripMenuItem m in master.DropDownItems)
//{
// //Drop Down items
//}
}
}
}
推荐答案
你可以使用如何遍历menuStrip控件中的所有菜单项的递归[ ^ ]提示轻松计算项目数。
You can use the How to iterate recursive through all menu items in a menuStrip Control[^] Tip to calculate Items count easily.
这篇关于如何计算菜单条和子菜单中的值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文