private void toolStripMenuItemOpen_Click(object sender, EventArgs e) { ContextMenuStrip tagged = (sender as ToolStripMenuItem).Owner as ContextMenuStrip; Console.WriteLine(tagged.Tag.ToString()); }
private void FreqGraph_ContextMenuBuilder(ZedGraphControl sender, ContextMenuStrip menuStrip, Point mousePt, ZedGraphControl.ContextMenuObjectState objState) { try { //每次循环只能遍历一个键 foreach (ToolStripMenuItem item in menuStrip.Items) { if ((string)item.Tag == "copy") { item.Text = "复制"; item.Visible = true; break; } } foreach (ToolStripMenuItem item in menuStrip.Items) { if ((string)item.Tag == "save_as") { item.Text = "另存图表"; item.Visible = true; break; } } foreach (ToolStripMenuItem item in menuStrip.Items) { if ((string)item.Tag == "show_val") { item.Text = "显示XY值"; item.Visible = true; break; } } foreach (ToolStripMenuItem item in menuStrip.Items) { if ((string)item.Tag == "unzoom") { item.Text = "上一视图"; item.Visible = true; break; } } foreach (ToolStripMenuItem item in menuStrip.Items) { if ((string)item.Tag == "undo_all") { item.Text = "还原缩放/移动"; item.Visible = true; break; } } foreach (ToolStripMenuItem item in menuStrip.Items) { if ((string)item.Tag == "print") { menuStrip.Items.Remove(item); item.Visible = false; //不显示 break; } } foreach (ToolStripMenuItem item in menuStrip.Items) { if ((string)item.Tag == "page_setup") { menuStrip.Items.Remove(item); //移除菜单项 item.Visible = false; //不显示 break; } } foreach (ToolStripMenuItem item in menuStrip.Items) { if ((string)item.Tag == "set_default") { item.Text = "初始化"; item.Visible = true; //不显示 break; } } } catch (System.Exception ex) { MessageBox.Show("初始化右键菜单错误" + ex.ToString()); } }