Reputation: 2379
I am trying to add a bunch of controls dynamically in rows and columns in a Windows Forms form. For example, if I have 20 controls and I need to create three columns and n rows. How do I achieve this?
Upvotes: 1
Views: 3961
Reputation: 6776
I agree with Tim.
However, if you know that you are always going to be adding the controls in sets of three, I would recommend creating a user control to contain the three.
Upvotes: 0
Reputation: 54734
Add a TableLayoutPanel
to your form. At runtime, instantiate your controls using the new
keyword. Add them to the tableLayoutPanel.Controls
collection. You can either add them to specific rows and columns, or let panel have them flow into the next available cell.
Upvotes: 8