To have the Controls appear from top-to-bottom ... in the order you added them to the Panel ... and have the other elements auto-size when you change their 'Height Property, or delete them, make them visible, or hide them:
1. add the newly added Controls to the host Panel's ControlCollection
2. set the newly added Controls 'Dock Property to 'Top
3. call 'BringToFront() on the newly added Controls
using System;
using System.Windows.Forms;
namespace YourNameSpace
{
public partial class MyAccordion : UserControl
{
public MyAccordion()
{
InitializeComponent();
}
private void MyAccordion_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
MyAccordionElement ele = new MyAccordionElement();
ele.SetText(i.ToString());
this.Controls.Add(ele);
ele.Dock = DockStyle.Top;
ele.BringToFront();
}
}
}
}
Here 'MyAccordionElement is another UserControl (code not shown).