如何遍历下拉菜单?
在一个自定义控件里边,想做成像窗口菜单那样,多选一的效果
this.选择ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.全部展开ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.全部合拢ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.选择ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.全部合拢ToolStripMenuItem,this.全部展开ToolStripMenuItem});
//菜单单击事件,设置选择点击菜单为 选择
void newmenu_Click(object sender, EventArgs e)
{
ToolStripMenuItem menu = (ToolStripMenuItem)sender;
menu.Checked = true
}
问题是下面的遍历不能取消所有原来选择的,只有 Enabled 却没有 Checked
for (int c = 0; c<选择ToolStripMenuItem.DropDownItems.Count;c++ )
{
选择ToolStripMenuItem.DropDownItems[c].Enabled = false;
}
有什么方法全部设置 DropDownItems 里边 Checked = false ?