Reputation: 2691
Hi Ladies and Gentlemans!
I have a MenuStrip
and want to have a ContextMenu
with same structure.
Can I use my MenuStrip
as ContextMenu
, or quick create ContextMenu
with DataSource from MenuStrip
?
Thanks!
Upvotes: 3
Views: 3391
Reputation: 244772
I do not believe that you can use an item from a MenuStrip
as a ContextMenuStrip
. I've run into this before, and I agree that a menu should be a menu, but they're apparently implemented as different controls because they require slightly different functionality under the covers.
However, you can use a ContextMenuStrip
as a drop-down menu for the MenuStrip
control. So you can achieve the behavior you're looking for by doing it the other way around. Design the ContextMenuStrip
however you want it, and then assign it to the DropDown
property for the top-level ToolStripMenuItem
on the MenuStrip
that you want that menu to be shown for.
Or, you can go the long way and create two different menus in the Designer, but copy-and-paste the items from one menu to the other. This at least saves you the time of designing two menus to look exactly the same. You can even wire up the event handlers (say, for the Click
events of each menu item) to handle the items from both menus. In VB.NET, for example, the Handles
keyword makes this extremely simple:
Private Sub Exit_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles exitMenuItem.Click, exitContextMenuItem.Click
Me.Close()
End Sub
Upvotes: 6