views:

167

answers:

2

I inherited the prototypical corporate application with a person form (with address, phone, etc).

Now on that mentioned person form one label+textfield is a child of the form itself and not of the panel it visually belongs to.

How can I change a control's parent from form to an existing panel in VS 2008 designer?

Update:

Ah, it seems to be a problem with the super magic custom group box control my beloved cow orker left for my pleasure. Dragging into a normal group box works ...

Update 2:

With the help of the Document Outline I can see that the custom "GroupBoxExt" we have in the application is defective, dragging a control onto the panel (or just changing position of a control on the panel) assigns it to the form.

Update 3:

Now that I new what was wrong (thanks for the document outline tip) I went of to google and found a custom group box on CodeGuru. The author of that artilce found out you'd need to decorate your custom panel with

[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]

to make it behave as a nice container.

A: 

I'm not sure exactly what your asking. Can you try clarifying the scenario a bit?

But if you want to change a controls parent, all you need to do is make that control a child of the panel using the Controls property.

myPanel.Controls.Add(target)

This should update the parent of target to be myPanel.

If you're attempting to do this via the designer, all you need to do is drag the target control onto the panel and that should take care of it.

JaredPar
Yes I want to do it using the designer (I have to rearrange a lot of stuff) but just dragging the control on the panel won't work with the "GroupBoxExt" my coworker built ... it will get assigned to the form, instead.
froh42
+1  A: 

If you're looking to do this in the designer, what you're looking for is the Document Outline panel (it's under the View menu under "Other Windows"). From there you can drag controls by their name in the outline and reassign the parent.

Hope this helps!

Adam Robinson
Ah great, document outline is what I was looking for. Seeing the outline it turns out the custom "GroupBoxExt" in the application is defective, as soon as I move a control it gets reassigned to the Form.
froh42
Accepting your answer as it moved my from despair into the right direction :-)
froh42