C#中如何遍历菜单?

(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;     //使此项不可用

                }
            }

posted @ 2017-11-01 15:35  mycls  阅读(507)  评论(0编辑  收藏  举报