winform Meunstrip 动态添加菜单(原)

界面放一个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 动态添加菜单(原)

上一篇:ActiveReports 报表应用教程 (1)---Hello ActiveReports


下一篇:使用Maven 、Jersey 和google protobuf 创建REST web service. windows7 32bit