开发者

Problem with order of Dock->Top controls

开发者 https://www.devze.com 2023-03-15 02:18 出处:网络
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 se

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?


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.


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.


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


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号