I customize the right click menu thanks to this :
lineGraphControl1.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler(MyContextMenuBuilder);
And
private void MyContextMenuBuilder(ZedGraphControl control, ContextMenuStrip menuStrip, Point mousePt, ZedGraphControl.ContextMenuObjectState objState)
{
// create a new menu item
ToolStripMenuItem item = new ToolStripMenuItem();
// This is the user-defined Tag so you can find this menu item later if necessary
item.Name = "simple_cursor";
// This is the text that will show up in the menu
item.Text = "Simple Cursor";
item.CheckOnClick = true;
// Add a handler that will respond when that menu item is selected
item.Click += new System.EventHandler(DisplaySimpleCursor);
// Add the menu item to the menu
menuStrip.Items.Add(item);
}
But the menu Simple Cursor
won't check when clicked. I try to force the sender in the function DisplaySimpleCursor()
, it doesn't work.
When I debug my app, I see that in DisplaySimpleCursor()
, the sender's property Checked is set to true.
What am I missing ?
As the menu is build on the heat, the checkOnClick
means nothing since the object is destroyed (I guess) everytime the menu is hidden.
The solution was to set the property :
// showOneCursor is a bool describing my need and toggled on click
item.Checked = showOneCursor;