Add controls dynamically in flowlayoutpanel
70,978
For a FlowLayoutPanel, you don't need to specify a .Location
since the controls are arranged for you:
Represents a panel that dynamically lays out its contents horizontally or vertically. ... The FlowLayoutPanel control arranges its contents in a horizontal or vertical flow direction. Its contents can be wrapped from one row to the next, or from one column to the next.
Just change "flowLayoutPanel1
" to the name of your FlowLayoutPanel
:
for (int i = 0; i < 5; i++)
{
Button button = new Button();
button.Tag = i;
flowLayoutPanel1.Controls.Add(button);
}
Author by
Karlx Swanovski
Updated on July 09, 2022Comments
-
Karlx Swanovski almost 2 years
In a windows form, I can add control dynamically by doing this:
for (int i = 0; i < 5; i++) { Button button = new Button(); button.Location = new Point(160, 30 * i + 10); button.Tag = i; this.Controls.Add(button); }
How do I add controls dynamically in a
FlowLayoutPanel
? -
Master Yoda over 9 yearsWhat on earth does SQL have to do with this question?
-
Mark almost 9 yearsHelped me as I am adding controls to a form from a database