2014-09-25 61 views
2

當我自定義右鍵菜單得益於此:點擊時定製Zedgraph ToolStripMenuItem不會檢查點擊

lineGraphControl1.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler(MyContextMenuBuilder); 

而且

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); 
} 

但菜單Simple Cursor不會檢查。我試圖強制發件人在功能DisplaySimpleCursor(),它不起作用。

當我調試我的應用程序,我看到在DisplaySimpleCursor(),發件人的屬性檢查設置爲true。

我錯過了什麼?

回答

0

由於菜單是建立在熱量基礎上的,checkOnClick沒有任何意義,因爲每次菜單被隱藏時,對象被破壞(我猜)。

的解決方案是設置屬性:

// showOneCursor is a bool describing my need and toggled on click 
item.Checked = showOneCursor;