日期:2014-05-17  浏览次数:20850 次

右键菜单多个子菜单的事件添加同一事

using System.Drawing.Printing;
在窗体Load事件中
            ContextMenuStrip cms = new ContextMenuStrip();
            cms.Name = "cms";
            cms.ImageList = this.toolIcon;
            ToolStripMenuItem mt1 = new ToolStripMenuItem("打印图纸");
            ToolStripMenuItem mt2 = new ToolStripMenuItem("另存图纸");
            ToolStripMenuItem mt3 = new ToolStripMenuItem("查看原始路径文件");
            ToolStripMenuItem mt4 = new ToolStripMenuItem("查看保存后的文件");
            mt1.ImageKey = "Print";
            mt2.ImageKey = "SaveAs";
            mt3.ImageKey = "CFile";
            mt4.ImageKey = "SFile";
            mt2.Click += new EventHandler(mt2_Click);
            mt3.Click += new EventHandler(mt3_Click);
            mt4.Click += new EventHandler(mt4_Click);
            if (Program.Usergroup == "工程部")
            {
                cms.Items.Add(mt1);
                cms.Items.Add(mt2);
                cms.Items.Add("-");
                cms.Items.Add(mt3);
                cms.Items.Add(mt4);
            }
            else
            {
                cms.Items.Add(mt1);
            }
            foreach (string Printer in PrinterSettings.InstalledPrinters)
            {
                //if (Printer != "Adobe PDF")
                {
                    ToolStripMenuItem printer = new ToolStripMenuItem(Printer, null, new EventHandler(mt1_Click));