Question Elements of a toolstrip witin an usercontrol get deleted when copying/pasting it.

priyamtheone

Well-known member
Joined
Sep 20, 2007
Messages
96
Programming Experience
Beginner
I have an usercontrol that contains a toolstrip. The toolstrip is exposed through the usercontrol by a readonly property 'HostStrip' with DesignerSerializationVisibility.Content attribute. In this way we can handle the toolstrip and its contents from the usercontrol.

While using the usercontrol in an application, after adding the elements of the toolstrip, if I copy the whole usercontrol and paste it somewhere else, the elements of the toolstrip get deleted. I need to add them all over again. Why is this happening and can it be solved?

Regards!
 
It happens because the toolstrip items are objects that can only belong to one ToolStrip. When you copy the Usercontrol+Toolstrip the items follows and is therefore removed from the previous collection. The ToolStrip itself as standalone will copy the items, this is because it has lots of designer services attached that create new items when it is copy/paste. When you copy/paste the usercontrol the ToolStrip is not currently designed, so those 'extras' doesn't take effect. A quick 'hack' is to enable design mode for the ToolStrip, see example http://www.vbdotnetforums.com/compo...rcontrol-acts-like-container-design-time.html (your uc property is of course for Toolstrip, and that is what you EnableDesignMode for in ControlDesigner)
 
Got the point. And an extra thanks for that briefing. Unties a load of knots.

But you see, as the toolstrip within the usercontrol can be selected explicitly, there's a possibility that the designer can delete it. I was expecting that the toolstrip cannot be handled directly by the designer but only through the 'HostStrip' property; while retaining the toolstrip items during copy/paste too. Can it be done somehow?

Please state if I'm not clear.
Regards!
 
Probably, but I haven't found it yet.
 

Latest posts

Back
Top