Windows Forms project, working only in designer (i.e. with mouse, before the compilation). I have a Form and 2 Panels in it. panel1 is docked (option - fill) in form1. panel2 is docked (fill) in form1, too. Also, panel2 is in front of panel1 (the latter is hidden behind the former). My problem is - when I undock panel2 and dock it again - it docks in panel1 (panel1 becomes it's parent) and not in form1. How can I change the parent of the panel2?
The only solution I figured out so far is cutting (ctrl+x) panel2, selecting form1 and then pasting (ctrl+v) panel2, but this, for some reason, removes all connections between panel2 controls and the code (for example clicking the button on panel2 doesn't work anymore although the function handling the event is still there).
Any better ideas?
Cutting controls to the clipboard will sever the event handlers, so best to stay away from cut and paste in the designer.
Since you are using the designer, open the Document Outline
panel from the View - Other Windows
menu in Visual Studio. Use the Arrow buttons to properly set the parent or the docking order of the controls.
The Document Outline window looks something like this:
Seems people liked my commented answer so I am putting it here as an answer
You can undock panel1, then move panel two out of panel1 onto the Form1 background. I have struggled with this as well. that was always my work around, I too found that cutting and pasting it cause a lot of haedaches. It can also be fixed in code, using the designer file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With