np.
np.

Reputation: 2379

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?

Upvotes: 1

Views: 3961

Answers (2)

Seattle Leonard
Seattle Leonard

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

Tim Robinson
Tim Robinson

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

Related Questions