Search code examples
c#winformspaneldocking

C# Panel docking issue


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?


Solution

  • 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:

    enter image description here