how to control array in C#

Posted on 2006-06-02
Last Modified: 2008-03-10
Hi Experts,

Is it pssible to create control array viz picture box, just like VB.

thanks in adance.
Question by:avinash_takale
    LVL 44

    Expert Comment

    you can create an Array of controls - in fact you cancreate an array of 'anything' - an array of Object

    but this is NOT the same thing as a VB 6 style Control Array -  .NET does NOT support control arrays in the same way that VB 6 did.

    LVL 5

    Expert Comment

    Do something like this:

    // if you want array of buttons
    Control[] controls = new Controls[10];
    for(int i = 0; i < 10; i++) controls[i] = new Button();


    LVL 2

    Accepted Solution

    this is another way:

    List<Control> myControls= new List<Control>();

    void InsertControls(int controlCount)

    for (int i=0; i<controlCount; i++)
        PictureBox pictureBox = new PictureBox();
        // pictureBox.Location = ....
        // set other properties


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 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

    16 Experts available now in Live!

    Get 1:1 Help Now