場景 在右鍵菜單ContextMenuStrip下添加子菜單選項可以通過 ContextMenuStrip menuStrip ToolStripMenuItem mnuChartOption = new ToolStripMenuItem(); //新建菜單項對象 mnuChartOption.N ...
場景
在右鍵菜單ContextMenuStrip下添加子菜單選項可以通過
ContextMenuStrip menuStrip ToolStripMenuItem mnuChartOption = new ToolStripMenuItem(); //新建菜單項對象 mnuChartOption.Name = "chart_option"; mnuChartOption.Text = "圖形選項"; //點擊彈出圖形選項對話框 mnuChartOption.Click += delegate(object sender, EventArgs e) { }; menuStrip.Items.Add(mnuChartOption);
來實現。但是如果在右鍵菜單的子菜單選項下再添加子菜單選項,形成二級子菜單。
註:
博客主頁:
https://blog.csdn.net/badao_liumang_qizhi
關註公眾號
霸道的程式猿
獲取編程相關電子書、教程推送與免費下載
實現
ToolStripMenuItem 的子級菜單仍然是ToolStripMenuItem ,主要通過DropDownItems屬性來構建關聯關係。
構建右鍵二級子菜單示例代碼
ToolStripMenuItem mnuDirectPrint = new ToolStripMenuItem("直接列印"); mnuDirectPrint.Name = "directPrint"; mnuDirectPrint.Text = "直接列印"; mnuDirectPrint.Click += delegate(object sender, EventArgs e) { control.DoPrint(); }; ToolStripMenuItem mnuPrintPageSet = new ToolStripMenuItem("列印頁面設置"); mnuPrintPageSet.Name = "printPageSet"; mnuPrintPageSet.Text = "列印頁面設置"; mnuPrintPageSet.Click += delegate(object sender, EventArgs e) { control.DoPageSetup(); }; ToolStripMenuItem mnuPrint = new ToolStripMenuItem(); mnuPrint.Name = "mnuPrint"; mnuPrint.Text = "列印"; mnuPrint.DropDownItems.Add(mnuDirectPrint); mnuPrint.DropDownItems.Add(mnuPrintPageSet); menuStrip.Items.Add(mnuPrint);
效果