Question How to Merge 2 ContextMenuStrips?

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I have 2 ContextMenuStrips already created. cmsMenu1 and cmsMenu2. Is there a way to make a cmsMenu3 that is cmsMenu1 + cmsMenu2?

I know i can do this with a dropdown menu

VB.NET:
cmsMenu3.Items.Clear()
cmsMenu3.Items.Add("Menu 1")
DirectCast(cmsMenu3.Items(0), ToolStripMenuItem).DropDown = cmsMenu1
cmsMenu3.Items.Add("Menu 2")
DirectCast(cmsMenu3.Items(1), ToolStripMenuItem).DropDown = cmsMenu2

but can it be done without the dropdown and have both cmsMenu1 and cmsMenu2 straight down in the first level?
 
Last edited:
With ToolStripManager you can Merge one strip to another, but the source strip will not work standalone after that until you RevertMerge. This is similar to doing Items.Add/AddRange with another strips Items, except such merge you can't "revert" as easily. The reason the source strip is not available until merge is reverted is because a menu item object can only have one parent.
 
Merge

ToolStripManager make cmsMenu3 works but in the process losing cmsMenu1 and 2. I need all 3 strips at the same time tho. Right now i am making cmsMenu3 by combining the code used to make menu1 and 2. I just thought there would be an easier way of doing it.

Couldn't i just do an addrange and copy cmsMenu1 to cmsMenu3 then do another addrange and copy cmsMenu2 to cmsMenu3?
 
No, as I said Merge/Add will move the menu item object because it can only be in one menustrip at a given time.
 
Back
Top