I am trying to mimic the behavior of, for example, Windows Explorer and how the Favorites items can launch a context menu.
I currently am using:
contextMenu.Show((sender as ToolStripMenuItem).GetCurrentParent().PointToScreen(e.Location));
This occurs in the MouseDown event of the ToolStripMenuItem. The problem is that the menu closes immediately after right-click, and I don’t know any way to suspend it while the context menu is open.
I’ve tried deriving from ToolStripMenuItem and overriding the MouseDown/MouseUp but I can’t figure out how to keep it open on click.
Is there a good way of doing this?
One way that you could accomplish this is by using the
ToolStripDropDowncontrol to host a ListBox inside of the ToolStripDropDown.This may require some tweaking regarding the
AutoClosebehavior, but it should get you started:First in your main form, add the following line to your ToolStripDropDropDown item
Then create a custom drop down class as follows:
In my tests this worked reasonably well. Let me know how it goes.