Recently. the layout of controls in net winform is confusing. Because the controls use the Dock method, the operation is convenient. If the control is maximized and the window size is adjusted, the window size changes.
But the problem is ,. net winform's dock method is to sort the priority docks according to the control order first added, suppose I want to have three controls A, B, and C respectively Fill the window in the Top, Bottom, and Fill modes, that is, the window should look like this:
---------------------
A
---------------------
C
---------------------
----------------------
Now, I want to add the D control in the center of A and C. What should I do? If you try a lot of methods, you will usually overwrite the C control, that is, the last added control.
Searching on the Internet, many people have proposed a helpless solution, that is, to add the control to the window form again, although it can solve the troubles caused by the Dock layout, however, it is difficult to adjust the workload to the same level as the previous layout.
This is not a solution. Add and Add. I always thought that the first control to be added has the priority of the Dock. You should be able to start from the Designer file.
Find the following code:
Copy codeThe Code is as follows: this. Controls. Add (this. D );
This. Controls. Add (this. C );
This. Controls. Add (this. B );
This. Controls. Add (this. );
Adjust the code order:Copy codeThe Code is as follows: this. Controls. Add (this. C );
This. Controls. Add (this. D );
This. Controls. Add (this. B );
This. Controls. Add (this. );
The problem is solved.
It can be seen that in the Desinger file, the controls added later are sorted by the Dock when the priority is high, that is, the sorting priority of control A is the highest.