ZedGraph怎样实现将图形右键菜单的打印和页面设置合并为打印的二级子菜单
<h1>场景</h1><p>Winforn中实现ZedGraph自界说添加右键菜单项(附源码下载):</p>
<p><a href="https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100140716">https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100140716</a></p>
<p>在上面博客实现的自界说右键以及汉化右键的根本上,怎样实现将自带的右键功能好比打印和页面设置归并为一个选项打印,并将上两个归并为其二级子菜单。</p>
<p>终极实现结果如下</p>
<p><img/></p>
<p>注:</p>
<p>博客主页: <br /><a href="https://blog.csdn.net/badao_liumang_qizhi">https://blog.csdn.net/badao_liumang_qizhi</a>
<br />关注公众号 <br />霸道的步调猿 <br />获取编程干系电子书、教程推送与免费下载。 </p>
<h1>实现</h1>
<p>起首在循环全部的menuStrip.Items时间,通过item.Visible =
false;将原来的打印与打印页面设置的item禁用。</p>
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;
}
}
<p> </p>
<p>然后在扩展右键菜单时自界说二级子菜单结果,并在子菜单中实验ZedControl的自带的右键变乱。</p>
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);
<h2>完整示例代码</h2>
<p>起首右键菜单变乱重新订阅</p>
zgc.ContextMenuBuilder -= zgc_ContextMenuBuilder; //上下文菜单天生变乱订阅
zgc.ContextMenuBuilder += zgc_ContextMenuBuilder; //上下文菜单天生变乱订阅
<p>然后在实现变乱中</p>
<p> </p>
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
}
页:
[1]