Create Dynamic Control Arrays

G

Guest

I have created a simple user control. On the parent form i would like to
display n instances of my usercontrol based on how many the user wants. How
would you do this in vb.net or c#.net. If this were an asp.net application i
think i could use something such as the repeater control.

Thanks.
 
G

Guest

I am assuming this is a win form app. To add a control dynamically, just
instantiate the control type, ie MyControl ctlr = new MyControl, set the
properties you need, ie
ctrl.Location = new Point(x,y); etc. then add the control to the form's
controls collection, frm.controls.Add(ctrl); (or this.control if executing
within the form)

does this help?

Tom Wisnowski
MCP MCAD
 
G

Guest

int currentY = 10; // starting y location
for (int i = 0; i < numControls; i++)
{
Control c = new Control();
c.Location = new Point(x, currentY);
// other init
this.Controls.Add(c);

currentY += 20;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top