3

由于这个原因,我自定义了右键菜单:

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(),发件人的属性Checked设置为 true。

我错过了什么?

4

2 回答 2

0

由于菜单是建立在热量之上的,因此checkOnClick每次隐藏菜单时对象都会被破坏(我猜),这意味着什么。

解决方案是设置属性:

// showOneCursor is a bool describing my need and toggled on click
item.Checked = showOneCursor; 
于 2014-09-26T07:57:11.950 回答
0

尝试这个。

 private bool check;
    public bool Check
    {
        get { return check; }
        set { check= value; }
    }
private void MyContextMenuBuilder(ZedGraphControl control, ContextMenuStrip menuStrip, Point mousePt, ZedGraphControl.ContextMenuObjectState objState)
{
    ToolStripMenuItem item = new ToolStripMenuItem();
    item.Name = "simple_cursor";
    item.Text = "Simple Cursor";
    item.CheckOnClick = true;
        item.Checked = Check; //add this
    item.Click += new System.EventHandler(DisplaySimpleCursor);
    menuStrip.Items.Add(item);
}


 private void DisplaySimpleCursor(object sender, EventArgs e)
        {
            Check = false==Check;
        }
于 2020-03-12T13:22:18.927 回答