ZedGraph怎样实现将图形右键菜单的打印和页面设置合并为打印的二级子菜单
程序员文章站
2022-06-22 12:15:22
场景 Winforn中实现ZedGraph自定义添加右键菜单项(附源码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100140716 在上面博客实现的自定义右键以及汉化右键的基础上,怎样实现将自带的右键功能比如打印和页 ......
场景
winforn中实现zedgraph自定义添加右键菜单项(附源码下载):
https://blog.csdn.net/badao_liumang_qizhi/article/details/100140716
在上面博客实现的自定义右键以及汉化右键的基础上,怎样实现将自带的右键功能比如打印和页面设置合并为一个选项打印,并将上两个合并为其二级子菜单。
最终实现效果如下
注:
博客主页:
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
首先在循环所有的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; //上下文菜单生成事件订阅
然后在实现事件中
private static void zgc_contextmenubuilder(zedgraphcontrol control, contextmenustrip menustrip, point mousept, zedgraphcontrol.contextmenuobjectstate objstate) { #region 扩展上下文菜单 #region 打印 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); #endregion #region 缩放 toolstripmenuitem mnureductlast = new toolstripmenuitem("还原上一步缩放"); mnureductlast.name = "mnureductlast"; mnureductlast.text = "还原上一步缩放"; mnureductlast.click += delegate(object sender, eventargs e) { control.zoomout(control.graphpane); }; toolstripmenuitem mnureductall = new toolstripmenuitem("还原所有缩放"); mnureductall.name = "mnureductall"; mnureductall.text = "还原所有缩放"; mnureductall.click += delegate(object sender, eventargs e) { control.zoomoutall(control.graphpane); }; toolstripmenuitem mnureduct = new toolstripmenuitem(); mnureduct.name = "mnureduct"; mnureduct.text = "缩放"; mnureduct.dropdownitems.add(mnureductlast); mnureduct.dropdownitems.add(mnureductall); menustrip.items.add(mnureduct); #endregion #endregion #region 汉化上下文菜单中的菜单项 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; } } #endregion }
上一篇: 配置 耶鲁大学的单点登录 【附图】
下一篇: Python - Unittest小结