An array of custom controls

Please see my screenshot:


As you can see I have a simple custom control.

I can place a bunch of these on the form.  That's okay..but it is not very dynamic.  The number is fixed.

But what I want is some kind of Container control that contains a bunch of these controls.

The number of custom controls inside the container control can increase or decrease at runtime.

It would go something like this:

//Drop the container control on the Form

//Behind the scenes it would be declared like this (for example....this would happen automatically)
CustControlContainer ccc = new CustControlContainer(  )

//Programmatically create custom controls to the Container

//This would add four controls...each one would take up a fourth of the space inside the Container control.

//This would delete 2 of the 4 controls.  The 2 remaining controls would resize in order to divide the available space in half.

//This would add 2 controls again...bringing the total number of controls back up to 4 controls...which would divide the Container control available space evenly.

I want to get this far....and then think about my next question.

I am not sure if this is exactly how the finished control will work...but it will get me started.



Tom KnowltonWeb developerAsked:
Who is Participating?
smeggheadConnect With a Mentor Commented:
You could have another usercontrol, which has the following

private OriginalControl[] AllControls;

private void BuildScreen()
      foreach (OriginalControl oc in AllControls)
            oc.Location=new Point(...,...); // Work out where to draw it
            oc.Size=new Size(...,...); // You'll have to work out the best size depending on the area you are drawing inside
public void AddCells(int Num)
      // Expand the size of the array (i.e. create a new array of the required size, and copy the original one into the new one.. then set the old array=new array

Does this help ?

Tom KnowltonWeb developerAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.