I have a code
void SomeButton_Click(object sender, EventArgs e)
{
if (this.Controls.Contains(Panel2))
{
this.Controls.Remove(Panel2);
}
else
{
this.Controls.Add(Panel2);
}
}
My problem is: the code changes document outline order of controls on my form. How can I restore previous document outline ? What properties, methods should I use ? Or is it impossible ?
Use Controls.SetChildIndex( Control child, int newIndex ) after adding the control to position it at the location you want it to be in. This only works if you know the exact location in the list the control is suppose to be in.
As an alternative, have you thought about adding all the panels and then setting Visible=false until you need to show them. This of course only works if the panels are all predefined. If you are dynamically creating them, then this will not work.