Keep MenuStrip open

Mayhem

New member
Joined
Jun 4, 2006
Messages
2
Programming Experience
5-10
I am trying to keep a Menu Strip from closing when clicking a checked ToolStripMenuItem. I figured it would be similar to the ContextMenu, but there is no Close Event for any of these objects. Any help/insight would be appreciated.
 
I don't have much time to solve this but for now I have a solution that works great.
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] TestToolStripMenuItem_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] TestToolStripMenuItem.Click
[/SIZE][SIZE=2][COLOR=#0000ff]     Me[/COLOR][/SIZE][SIZE=2].ToolStripDropDownButton1.ShowDropDown()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

You can't use this in the DropDownItemsClicked event b/c that event is processed before it closes and you can't use it in the DropDownItemsClosed Event (why I don't know). But you can use it in the individual buttons click event.

You are going to have to paste that inside of each buttons clicked event in the dropdownlist. It is actually closing the items but it's reopening them so fast you won't notice much. Maybe a slight flicker. Best I can offer for now. I tested it in a sample program and there ya go. :)
 
Interesting answer ImDaFreaK.. I was going to make some different suggestions if you hadnt found an answer:

Clicking the right mouse button doesnt dismiss a menu, but you can catch it in the MouseDown.. so you can put in your mousedown soemthing like:
VB.NET:
If(e.Button == RightMouseButton)
 'set this item checked and all others not checked
End If
Only thing is that right clicking a menu item isnt first nature for most users so you'd need a tooltip or soemthing to tell them

Or

You could use mouseover/mousehover for more than X time to change the option

Or

You can make a menu item into a combo box. Selecting an entry from the combobox list doesnt dismiss the menu, so you can put all the search options on the list. This is kinda cool cause you can make it more dynamic, link it to a database or something.. so if you add a new search by option, then its just a case of adding a line to a DB table.

Note also: comboboxes can either be drop down list or editable-textbox-with-list style, so you could make your list items like artist:, title:, genre:, album:
when the user selects an item, the text in the box changes to that item, then you can set the caret position to the end of the text, and they can type their search term.
advanced users could not bother with the list at all and simply type "artist: duran duran" and press return..

Then i started thinking about unambiguous abbreviation of the search terms.. like ar: for artist, and al: for album.. and then i got lost in another world of a different problem to yours all together.. SUch is the way of working on boring projects at work- distractions are nice :)
 
That's good information. I will look into the mouse down event and all. As for now I do think i have the best option for myself b/c it's not a choice of one checkbox of the other but any combination of the four. So a combobox wouldn't be suffice (although that's a better solution for the scenario you mentioned) and like you mentioned as well; the user doesn't usually go for right click to change options. But I still appreciate this extra knowlesge, i'm sure sometime it will come in handy. :)
 
Ok, realize this hasn't been reapproached for a while, but i am looking at this now.
The method may work in the case of a drop down in a menu, but what about without one?
Has there been a new discussions on this subject at all?
 
Back
Top