Is it possible to leave a ContextMenuStrip open after a selection/check of certain items?
I plan on using a simple ContextMenuStrip to set a filter (this way i could use the same filter either in a menu or as a right-click option).
The menu lists a number of items, and i would like the user to be able to make a selection of the items using the basic Check functionality. Once the selection is done the user can click an Activate filter option or can click outside the menu to either activate or cancel the filter.
On a selection/click event the menu normally closes. Is it possible to keep the menu open on a click event?
In case future programers are wondering how to do this, this is what I figured out. This will not close the context menu if any item is clicked. Create the context menu strip closing event and setup an if statement to cancel the close event if close reason is itemclicked.
private void contextMenuStrip_Closing(object sender, ToolStripDropDownClosingEventArgs e)
{
if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
e.Cancel = true;
}
the Closing event
set e.Cancel = true to leave the menu open
only problem is the event doesn't tell you what was clicked, so you have to keep track of this yourself. set some kind of flag in the Click event of the items you want to keep the menu open. then in the Closing event check the flag and set e.Cancel appropriately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With