C # panel docking issue

A Windows Forms project that works only in a designer (i.e. with a mouse, before compilation). I have a form and 2 panels. Panel 1 is fixed (option - fill) in form1. panel2 is also docked (filled) in form1. In addition, panel2 is located in front of panel 1 (the latter is hidden behind the first). My problem is that when I unlock panel2 and again its dock, it joins panel 1 (panel1 becomes its parent), and not in form1. How to change the parent element of panel2?

The only solution I've figured out so far is to cut out (ctrl + x) panel2, select form1, and then paste (ctrl + v) panel2, but this for some reason removes all connections between the panel2 controls and the code ( for example, pressing a button on panel2 no longer works, although the event handling function still exists).

Any better ideas?

+5
source share
3 answers

Cutting controls to the clipboard with the separation of event handlers, so it is better to avoid cutting and pasting in the constructor.

Since you are using the constructor, open the form Document Outlinefrom the menu View - Other Windowsin Visual Studio. Use the arrow buttons to set the parent or dock order of controls correctly.

" " :

enter image description here

+6

, ,

1, 1 Form1. . , , . ,

+1

The panel cannot change the parent when you change the dock !!! Or I really do not understand your problem.

But ... if you want to change the parent. Just remove the Control Panel list panel and add it to the Control list of the form.

yourPanel.Controls.Remove(yourOtherPanel);
yourForm.Controls.Add(yourOtherPanel);
yourOtherPanel.Dock = .....;
0
source

All Articles