Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a user control called PumpControl1. How can I add x number of these to my form frmMain? I obviously want them to be drawn correctly and not over one another.

thanks,

Mike.
Posted

Jibrohni wrote:
How can I add x number of these to my form frmMain?

You may, for instance, add an array of PumpControl as member of the class.


Jibrohni wrote:
I obviously want them to be drawn correctly and not over one another.

This is up to you (i.e. set properly the position and size of the components when you add them to the form).
:)
 
Share this answer
 
Comments
Jibrohni 25-May-10 8:39am    
Ok, great, so how do I then draw a new user control for each of them in my usercontrol List?

PumpControlList

I.e, say I want to draw them at a width of 240 pixels each time, how would I code the following?

foreach (PumpControl p in PumpControlList)
{

}
#realJSOP 25-May-10 9:34am    
To Jibrohni - Well, in your loop that creates the control, change the size and position after the control is created. It ain't rocket science...
PumpControl1 pc1A = new PumpControl1();
// position as required (you're going to have to figure this out on 
// your own because we don't know where you want them to be position.


Repeat as necessary, like so:

PumpControl1 pc1B = new PumpControl1();


Like CPalinni CPallini mentioned, you could put them into a List (or even a Dictionary so you could refer to them by name or numeric ID, or whatever). If you're going to do this, though, I would create a method that creates a single control instance and then adds that instance to your collection.
[Careful John... in the suitcase on the left I'll find my favorite axe. - Carlo]
 
Share this answer
 
v2
You can use an array or List to store the controls as suggested in the previous answers.

To display them you can use TableLayoutPanel container. Dynamically add ColumnStyle and RowStyle and add the pump control to a particular cell as
tblPanel.Controls.Add(new PumpControl(), 0, 0);




By doing this you don't need to worry about the location of the control in form. You can also make the TableLayoutPanel scrollable if the total number of your control exceed the size.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900