ToolStripMenuItem does not close when ToolStripMenuItem child object is clicked in C # WinForm

Is there a way to prevent the ToolStripMenuItem from closing when I click on a child control (in its DropDrowItems collection)?

In my case, I have some ToolStripMenuItems that work like a checkbox. In fact, I applied the radio behavior in some ToolStripMenuItems using the Check property. But I don’t want the menu to close when I click on any of them, because they are not an action, they are only parameters in the menu item.

Is it possible?

+3
source share
3 answers
   this.menuItem.DropDown.Closing += new ToolStripDropDownClosingEventHandler(DropDown_Closing); 

void DropDown_Closing(object sender, ToolStripDropDownClosingEventArgs e)
            {
                if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
                {
                    e.Cancel = true;
                    ((ToolStripDropDownMenu) sender).Invalidate();
                } 
            }
+4
source

:

  • ContextMenuStrip ToolStripDropDown.
  • ContextMenuStrip ( ) ToolStripMenuItem (), ToolStripDropDown ToolStripMenuItem!
  • ToolStripDropDown (. Zabulus).
0

Source: https://habr.com/ru/post/1733525/


All Articles