界面放一个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("!!!!!!"); }