How to make an array of Forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • snehil
    New Member
    • Jun 2009
    • 19

    How to make an array of Forms

    Hey,
    Can any one help me with this problem.. i'ld really appreciate ne help..
    wat i wanna do is.. dat i want to dynamically create objects on a way that they could be created in a loop..
    so i thot an array of object could help
    so i went ahead and wrote this code in a form load event..
    Code:
    Form1[] formarray = new Form1[4];
    for (int i = 0; i < 4; i++)
        {
            formarray[i] = new Form1();
            formarray[i].Show(); 
        }

    but at the line

    Code:
    formarray[i].Show();
    I get this exception
    Error creating window handle.
    As u mite have guessed from the code.. wat i wanna do is to open 'n' no. of forms while loading.. and n will differ every time .. actually it will depend upon the no of records in some table and i want the no. of forms to be equal to the no. of records.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    I reproduced your code (kinda... more in a sec) and it actually worked fine. Maybe post more details... specifically, the full source?

    I noticed you had it in the Form's Load event. Is Form1 your main form or another form? Obviously it's going to produce an infinite, exponential loop as each form would generate four new forms. However, it still worked and I didn't get an exception ;)

    Comment

    Working...