Search code examples
c#contextmenuzedgraph

How to remove a specific context menu item in Zedgraph


I want to remove a specific context menu item, appears when the Mouse down(right) event is fired.

enter image description here

with the help of Context Menu Builder event, I was able to add some costume menu items, but I want to get rid off the last item(Default).

Thanks in advance...


Solution

  • In the same event handler, you can remove items as well, for example:

    private void zedGraphControl1_ContextMenuBuilder(ZedGraphControl sender, ContextMenuStrip menuStrip, Point mousePt, ZedGraphControl.ContextMenuObjectState objState)
    {
      foreach (ToolStripMenuItem item in menuStrip.Items)
      {
        if ((string)item.Tag == "set_default")
        {
          menuStrip.Items.Remove(item);
          break;
        }
      }
    }
    

    Relevant Link: http://goorman.free.fr/ZedGraph/zedgraph.org/wiki/index43d0.html?title=Edit_the_Context_Menu