Adding controls dynamically on a Windows Forms form
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?
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.
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.