In-depth analysis of the Dock sequence adjustment of the WinForm control in C #

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.