private void AddPanel(Panel target)
{
int nControls = target.Controls.Count;
Panel p = new Panel
{
Margin = new Padding(3),
Anchor = AnchorStyles.Left | AnchorStyles.Top,
Location = new Point(0, (nControls * 152)),
Size = new Size(280, 150),
BackColor = Color.AliceBlue,
BorderStyle = BorderStyle.Fixed3D
};
target.Controls.Add(p);
}
If you want the Panels flush, then set their Dock property; example:
private void AddDockedPanel(Panel target)
{
int nControls = target.Controls.Count;
Panel p = new Panel
{
Dock = DockStyle.Top,
Size = new Size(280, 150),
BackColor = Color.AliceBlue,
BorderStyle = BorderStyle.Fixed3D
};
target.Controls.Add(p);
p.BringToFront();
}