private void ResizePanel(object oPanel, ControlEventArgs e) { FlowLayoutPanel pnl = (FlowLayoutPanel)oPanel; int w = pnl.Width; if (pnl.Parent.Width > pnl.Width) // make sure we don't adjust position if it fills entire space { pnl.Left = (pnl.Parent.Width - pnl.Width) / 2; } pnl.Width = ((pnl.Height - 3) * pnl.Controls.Count) + 5; }