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 //} } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)