场景
Winforn中实现ZedGraph自界说添加右键菜单项(附源码下载):
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100140716
在上面博客实现的自界说右键以及汉化右键的根本上,怎样实现将自带的右键功能好比打印和页面设置归并为一个选项打印,并将上两个归并为其二级子菜单。
终极实现结果如下
注:
博客主页: https://blog.csdn.net/badao_liumang_qizhi
关注公众号 霸道的步调猿 获取编程干系电子书、教程推送与免费下载。
实现
起首在循环全部的menuStrip.Items时间,通过item.Visible =
false;将原来的打印与打印页面设置的item禁用。
- foreach (ToolStripMenuItem item in menuStrip.Items)
- {
- switch (item.Name)
- {
- case "copied_to_clip":
- item.Text = @"复制到剪贴板";
- break;
- case "copy":
- item.Text = @"复制";
- item.Click += item_Click;
- break;
- case "page_setup":
- item.Text = @"打印页面设置";
- item.Visible = false;
- break;
- case "print":
- item.Text = @"打印";
- item.Visible = false;
- break;
- case "save_as":
- item.Text = @"另存图表...";
- break;
- case "set_default":
- item.Text = @"规复默认巨细";
- break;
- case "show_val":
- item.Text = @"体现节点数值";
- item.Visible = false;
- break;
- case "title_def":
- item.Text = @"标题";
- break;
- case "undo_all":
- item.Text = @"还原全部缩放";
- item.Visible = false;
- break;
- case "unpan":
- item.Text = @"还原上一步缩放";
- item.Visible = false;
- break;
- case "unzoom":
- item.Text = @"还原缩放";
- item.Visible = false;
- break;
- case "x_title_def":
- item.Text = @"X 轴";
- break;
- case "y_title_def":
- item.Text = @"Y 轴";
- break;
- }
- }
复制代码
然后在扩展右键菜单时自界说二级子菜单结果,并在子菜单中实验ZedControl的自带的右键变乱。
- 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);
复制代码
完整示例代码
起首右键菜单变乱重新订阅
- zgc.ContextMenuBuilder -= zgc_ContextMenuBuilder; //上下文菜单天生变乱订阅
- zgc.ContextMenuBuilder += zgc_ContextMenuBuilder; //上下文菜单天生变乱订阅
复制代码
然后在实现变乱中
|