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.

Need Your Help

What makes Ruby an Elegant Language?

ruby-on-rails ruby

I have been reading a lot about Ruby the past few days. Every SO post I come across I hear that ruby is an elegant language. Can you guys give an example of why ruby is elegant compared another lan...

check if element is present

java selenium webdriver

I use selenium web-driver in Eclipse.I need to check if table is displayed on page. I use such code: