ContextMenuStrip 添加二级菜单,为什么二级菜单不能Checked?一级菜单却可以

解决方案 »

  1.   

    可以啊。
    把下面的代码添加到InitializeComponent函数试试:
    private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
            private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
            private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
    this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
                this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
                this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
    // 
                // contextMenuStrip1
                // 
                this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
                this.toolStripMenuItem1});
                this.contextMenuStrip1.Name = "contextMenuStrip1";
                this.contextMenuStrip1.Size = new System.Drawing.Size(181, 26);
                // 
                // toolStripMenuItem1
                // 
                this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
                this.toolStripMenuItem2});
                this.toolStripMenuItem1.Name = "toolStripMenuItem1";
                this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
                this.toolStripMenuItem1.Text = "toolStripMenuItem1";
                // 
                // toolStripMenuItem2
                // 
                this.toolStripMenuItem2.Checked = true;
                this.toolStripMenuItem2.CheckState = System.Windows.Forms.CheckState.Checked;
                this.toolStripMenuItem2.Name = "toolStripMenuItem2";
                this.toolStripMenuItem2.Size = new System.Drawing.Size(180, 22);
                this.toolStripMenuItem2.Text = "toolStripMenuItem2";
      

  2.   

    我写错了,是可以被Checked。
    是因为我的一级菜单单击的时候相应的是MyMenu_itemChecked()事件
    二级菜单为什么不能相应这个事件呢?
      

  3.   

    我写错了,是可以被Checked。 
    是因为我的一级菜单单击的时候相应的是MyMenu_itemClicked()事件 
    二级菜单为什么不能相应这个事件呢?
      

  4.   

    你应该把二级菜单的CheckOnClick = true;
      

  5.   

    二级菜单还是不能响应MyMenu_itemClicked()事件 
    为啥呢?
      

  6.   

    二级菜单的itemClicked事件是否挂接了MyMenu_itemClicked函数?
    例如:
    this.toolStripMenuItem2.CheckedChanged += new System.EventHandler(this.toolStripMenuItem2_CheckedChanged);
    上面的toolStripMenuItem2是二级菜单,toolStripMenuItem2_CheckedChanged函数相当于MyMenu_itemClicked;
    查找你的代码中是否也有对应的代码。