Winform Panel controls in reverse order

Today, when you add multiple instances of a Panel control in a C # loop, find the newly added controls at the top, rather than the final surface, the order is completely reversed. We can reverse the controls need to add to solve this problem, but not the best solution.

After setting it is the best solution every time you add a control ah ChildIndex, always set to 0 on it. Such acquired additional controls in the following, rather than the front.

            for (int i = 0; i < 10; i++)
            {
                Label lbl = new Label();
                lbl.Text = i.ToString();
                panelMain.Controls.Add(lbl);
                panelMain.Controls.SetChildIndex(lbl, 0);
            }

 

Published 30 original articles · won praise 10 · views 40000 +

Guess you like

Origin blog.csdn.net/alai7150/article/details/104077634