我有一个 TreeView 控件,其中的每个节点我想共享一个具有两个 ToolStripMenuItem 的 ContextMenuStrip,即:
this.BuildTree = new MyApp.MainForm.TreeView();
this.ItemMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.DeleteMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShowLogMenuItem = new System.Windows.Forms.ToolStripMenuItem();
...
this.ItemMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.DeleteMenuItem,
this.ShowLogMenuItem});
因此,我在 MouseUp 事件中右键单击时根据某些条件显示和隐藏这些项目。当两者都被隐藏时,我隐藏了 ContextMenuStrip 本身。问题是当我隐藏 ContextMenuStrip 时,似乎下次我想显示其中一个菜单项时,我必须在节点上单击两次。奇怪的是在第一次单击以重新显示一个或两个项目时,我有以下代码:
ItemMenuStrip.Visible = true;
ShowLogMenuItem.Visible = true;
上面的两行似乎没有做任何事情,即在跨过每一行之后在调试器视图中都保持错误。
我认为我没有设置这些值的任何事件,至少我没有附加任何事件。
我究竟做错了什么?