multiple forms

  • Thread starter Thread starter Kate
  • Start date Start date
K

Kate

I have a project with 2 forms within it.
From the form1 I need to take data into form2;
In form2 further data added & calculations done.
I then need to return to form1 again with form2 data, whilst still retaining
the original data (form1).
The problem I have is opening form1 from form2, how do you do it?? I
declared an instance of form1 as
formName as New form1()
at the top of form2, but of course this only create a new instance of form1

I have set form1 IsMDIContainer to true and added a new form to it (form2)
with same property set to false, but don't know how to reference form1, how
do I declare from1??


Sorry if this sounds complicated, I just need to share data between 2 forms
and open and close 'only one' instance of each form.

TIA
Kate
 
Kate,

Ok this is what I think you have....

Form1 is a parent form which contains Form2 as a MDI child form.

There are several ways to tackle this. Some are more OO than others... Up
to you how you want to implement it.

1) In Form1 have some public property or function
Form 2 has a property to set who you want to send data to (i.e. Form1
type or possibly (?) use the parent property and cast it).
Stores the value in a variable
Form1 then sets itself to this property. (e.g.
Form2.whateverformtypeproperty = this; )
Then when Form2 wants to send data it just uses whatever was set in the
variable.

Of course this does mean form1 knows about form 2 and form2 knows about
form1... (which most will say is bad design).

2) Use events
Form1 instantiates Form2 and subscribes to a datachanged type event.

Form1 sets data in Form2.
Form2 does what it needs to do then fires the event to say it has
changed it.
Form1 gets the event, gets the data from Form2 and does whatever it
likes to the data.

There are probably other equally good \ stupid ways.

Does that help?

rollasoc
 
Back
Top