首页 > 代码库 > winform Meunstrip 动态添加菜单(原)
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 动态添加菜单(原)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。