I have a place in my code where I dynamically add controls to the top-down FlowLayoutPanel. I need the controls to appear in a specific order, so every time I do a cleanup of the FlowLayoutPanel.Controls collection, and then add each child control in the order that I want them to be displayed. My code does this:
private void arrangement1()
{
flowLayoutPanel1.Controls.Clear();
flowLayoutPanel1.Controls.Add(control1);
flowLayoutPanel1.Controls.Add(control2);
flowLayoutPanel1.Controls.Add(control3);
}
In most cases, this works great. However, there is one specific control that does not retain its position in the control collection when other controls are added after it. For example, in the following code segment:
private void arrangement2()
{
flowLayoutPanel1.Controls.Clear();
flowLayoutPanel1.Controls.Add(control1);
flowLayoutPanel1.Controls.Add(movingControl);
//movingControl current is at index = 1 in Controls.
flowLayoutPanel1.Controls.Add(control2);
//control2 is now at index = 1, movingControl got bumped to index = 2 in Controls.
flowLayoutPanel1.Controls.Add(control3);
//control3 is now at index =2, movingControl got bumped to index = 3 in Controls.
}
MoveControl Controls. 1, 2 . :
- control1
- movingControl
- Control2
- Control3
, Controls.Add. , .Add , . - , . "" :
arrangement2();
arrangement1();
arrangement2();
- .
!
EDIT: , , Controls. - . . , . GUI- . , , , , . , .
, , Controls.Add . , Clear() NO Remove().