Reputation: 26919
C# WinForms: I am designing my form and I have a couple of TableLauots. so I design my first tablelayout, throw it on the panel and set Dock->Top ... then I design my second one and do the same and set Dock->Top, it goes to Top again and good, it places under the previous one that was on top...I design the third one and set its dock.top and good it is under second one which is under first one...but I dunno what is the diffrence for the forth one that when I set its dock.top, it changes the order of the other three ones and get places some where in between them, it does not get placed under the third one...any idea what should I look in to?
Upvotes: 14
Views: 21475
Reputation: 951
You can change the ordering of a control to move to a particular index
containerPanel.Controls.SetChildIndex(Control, n); //sets control to be the Nth element from the bottom
Upvotes: 4
Reputation: 14781
It depends on the order you have added those controls to their container. The earlier added control will be the topper one and so on ...
To fix it, "Cut" the forth control and "Paste" it again to the container and it will take the desirable place.
Another way to fix it is by modifying the designer file code to re-order the adding of those controls to their container.
Upvotes: 37
Reputation: 5637
The dock layout is based on the order they are added to the container.
I usually go to the *.Designer.cs file and modify the InitializeComponent() method to manually re-order how the controls are added to the container.
this.Controls.Add(this.panel1);
this.Controls.Add(this.panel4);
this.Controls.Add(this.panel3);
this.Controls.Add(this.panel2);
This order is opposite on display
Upvotes: 9
Reputation: 1804
You have to organize the order of your controls in the Document Outline window (VIEW -> Other Windows -> Document Outline (Ctrl+W, U)). Select your form in Desing Mode and you will see all your components in a tree view. Use the arrows on the top to select the desired order.
It is better than cut and past because it will avoid loss of binding callbacks.
Upvotes: 8
Reputation: 52788
Right click on the Controls and select "Send to Back" or "Bring to Front", or use the Document Outline Window to rearrange the Z-Order of the items. Document Outline helps a lot when creating WinForms things with lots of controls.
Upvotes: 22