locked
Generate forms programatically? RRS feed

  • Question

  • is it possible to create multiple forms from a single main form?

    here's what i think:

    the user will put a certain number on the current form and once the form's button was click, the program will generate that many forms. is it possible?
    Wednesday, January 14, 2009 3:45 AM

Answers

  • This might help

     Form x1[] = new Form[numberOfForms];

    -- Please mark as answer if it solves the problem
    • Marked as answer by sniperL96 Thursday, January 15, 2009 7:36 AM
    Wednesday, January 14, 2009 3:58 AM
  • SniperL96,

    form is just an object. So if you create array of any objects (forms in this case), you can work with them separately.
    //Button Click Event  
    private void button_Click(object sender, EventArgs e)  
    //Declare Array of Form Objects - numberOfForms is value of TextBox (for example)   
    Form[] arrayOfForms = new Form[numberOfForms];  
    //Create desired number of Form instances  
    for (int i = 0; i <= numberOfForms; i++)  
    {  
    arrayOfForms[i] = new Form();  
    }   
    //Now you can work with Forms  
     
     
     
    Is it clear?

    SaltFish
    Salty and chilled, but always coded!
    • Marked as answer by sniperL96 Thursday, January 15, 2009 7:36 AM
    Wednesday, January 14, 2009 5:21 AM

All replies

  • This might help

     Form x1[] = new Form[numberOfForms];

    -- Please mark as answer if it solves the problem
    • Marked as answer by sniperL96 Thursday, January 15, 2009 7:36 AM
    Wednesday, January 14, 2009 3:58 AM
  • can you explain it to me further on how it would work?

    much appreciated
    Wednesday, January 14, 2009 4:04 AM
  • SniperL96,

    form is just an object. So if you create array of any objects (forms in this case), you can work with them separately.
    //Button Click Event  
    private void button_Click(object sender, EventArgs e)  
    //Declare Array of Form Objects - numberOfForms is value of TextBox (for example)   
    Form[] arrayOfForms = new Form[numberOfForms];  
    //Create desired number of Form instances  
    for (int i = 0; i <= numberOfForms; i++)  
    {  
    arrayOfForms[i] = new Form();  
    }   
    //Now you can work with Forms  
     
     
     
    Is it clear?

    SaltFish
    Salty and chilled, but always coded!
    • Marked as answer by sniperL96 Thursday, January 15, 2009 7:36 AM
    Wednesday, January 14, 2009 5:21 AM
  • Hi,
    yes you can ,the replies work, but I think you choose wrong solution for your problem,
    If you tell me what you want to do maybe I can give you better solution than creating many forms.
    ofcourse you do not want emty forms. so please explain more about your problem.
    I am waiting
    Ali
    Pishkari
    • Proposed as answer by pishkari Thursday, January 22, 2009 7:13 AM
    Wednesday, January 14, 2009 9:54 AM