Custom Zedgraph ToolStripMenuItem赢得';t单击时进行检查

本文关键字:单击 进行检查 Zedgraph ToolStripMenuItem 赢得 Custom | 更新日期: 2023-09-27 18:24:19

由于以下原因,我自定义了右键菜单:

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。

我错过了什么?

Custom Zedgraph ToolStripMenuItem赢得';t单击时进行检查

由于菜单是在高温下构建的,checkOnClick没有任何意义,因为每次隐藏菜单时对象都会被破坏(我想)。

解决方案是设置属性:

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

试试这个。

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