Repeating controls with c#

c#, custom-controls, windows, winforms

Solution

You can create a UserControl (Add > New Item... > User Control)

public partial class WFUserControl : UserControl
{
}

And add on a container control, such as a panel

panel1.Controls.Add(new WFUserControl());

To make it add one bellow another you can use a `TableLayoutPanel`, set `AutoSize` to `true`, set only one column and only one row. Then when you add 3 controls it will look like this:

Problem

I've been into web for long, but now I should do a little c# project and I'm wondering how I can make such repeat: In web I can just do ``` <div id="holder"> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div> ``` and even add it dynamicly: ``` var items = [{}, {}, {}, {}]; for ( var i in items ) { $("#holder").append("<div class=\"item\"></div>"); } ``` and render as much items as represented in the array. My actual question is how to use exactly User Control?

Original source