Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 455
NPS Avatar asked May 31 '12 14:05

NPS


2 Answers

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

like image 95
LarsTech Avatar answered Sep 30 '22 01:09

LarsTech


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

like image 33
General Grey Avatar answered Sep 30 '22 02:09

General Grey