Form Instance

Ok. I have 3 forms. On form1 I want to declare an instance of form1. How would I make this new instance available to the other forms Can someone help me


Answer this question

Form Instance

  • mehdi mousavi

    What do you mean by 'available' How are you creating and showing these forms Why do you need two instances of the same form



  • LostInSwindon

    hi cgraus,

    I was just having an example to put it on the form_load event.

    He can try it using the button_click event.



  • urkumar2000

    Hi,

    To declare a new instance of a form:
    ex:
            Form1  myform1 = new Form1();

    If you want to access your form to other form:

    ex:

    Put this code in your form1 load event:

             Form2 myform2 = new Form2();
             myform2.Show(this);
             Form3 myform3 = new Form3();
             myform3.Show(this);

     

    HTH,

    Michael Castillones



  • Tadeusz

    Sure - he can do it where-ever he wants, so long as the form variables are member variables and not local to the event.



  • Walter Leinert

    Well - if you create the form in your load event, instead of as a member variable, how will you access it later I assume the child can use it's Parent property to access Form1, but in the other direction, I doubt it would work. This would also create tightly coupled code, you'd need to cast the Parent to a Form1 to get any non base class methods. Using delegates for interation between classes is more loosely coupled, and therefore better.



  • Form Instance