(1)横向遍历 ToolStripMenuItem
foreach (ToolStripMenuItem con in this.MainMenuStrip.Items)
{
}
(2)纵向遍历 ToolStripItem
foreach (ToolStripItem con2 in con.DropDownItems)
{
if (con2 is ToolStripMenuItem)
if (con2.Tag == "10")
con2.Enabled = false; //使此项不能选
// con2.Visible= false; //使此项不可用
}
(3)先横后纵遍历
foreach (ToolStripMenuItem con in this.MainMenuStrip.Items)
{
foreach (ToolStripItem con2 in con.DropDownItems)
{
if (con2 is ToolStripMenuItem)
if (con2.Tag == "10")
con2.Enabled = false; //使此项不能选
// con2.Visible= false; //使此项不可用
}
}
如果能与数据库结合,就可以实现“角色”功能。例如,在系统中实现过。