An array of custom controls

Posted on 2005-04-20
Last Modified: 2010-04-16
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.



Question by:knowlton
    LVL 10

    Accepted Solution

    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 ?

    LVL 5

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now