码迷,mamicode.com
首页 > Windows程序 > 详细

winform Meunstrip 动态添加菜单(原)

时间:2015-01-27 13:04:53      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:

界面放一个Meunstrip控键

//清空菜单项
        private void CleaarMenuMain()
        {
            foreach (ToolStripMenuItem item in menuMain.Items)
            {
                item.DropDownItems.Clear();
                item.Visible = true;
            }
        }

  

//初始化菜单
        private void InitMemuMain()
        {
            CleaarMenuMain();

            ToolStripMenuItem tsmi;
            ToolStripMenuItem tsmiSub;

            //添加菜单
            tsmi = new ToolStripMenuItem("a");
            tsmiSub = new ToolStripMenuItem("a1", null, tsmiSub_Click, "tsmiName");
            tsmi.DropDownItems.Add(tsmiSub);
            tsmiSub = new ToolStripMenuItem("a2", null, null, "tsmiName");
            tsmi.DropDownItems.Add(tsmiSub);
            menuMain.Items.Add(tsmi);

          //添加菜单
            tsmi = new ToolStripMenuItem("b");
            tsmiSub = new ToolStripMenuItem("b1", null, tsmiSub_Click, "tsmiName");
            tsmi.DropDownItems.Add(tsmiSub);
            tsmiSub = new ToolStripMenuItem("b2", null, null, "tsmiName");
            tsmi.DropDownItems.Add(tsmiSub);
            menuMain.Items.Add(tsmi);
        }
 //菜单点击事件具体实现
        private void tsmiSub_Click(object sender, EventArgs e)
        {
            MessageBox.Show("!!!!!!");
        }

  

  

winform Meunstrip 动态添加菜单(原)

标签:

原文地址:http://www.cnblogs.com/mowuyan/p/4252251.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!