I have two forms and form1 needs to get data from form2, i use a parameter in form2 constructor to gets form1's instance like this:
public form2(Form form1) {
this.f = form1;
}
and in form1:
Form form2 = new Form(this);
But it seem form1 destruct was called when i closed form1. my question is how can i avoid this problem?
EDIT: I have many typing mistakes in my question, i’m so sorry, fixed:
I have two forms and form2 needs to get data from form1, i use a parameter in form1 constructor to gets form1's instance like this:
private Form f;
public form2(Form form1) {
this.f = form1;
}
and in form1:
Form form2 = new Form(this);
But it seem form1 destructor was called when i closed form2. my question is how can i avoid this problem?
from MSDN:
As such, to prevent disposal of the resources, the only thing you can do is hide the form instead of closing it:
This will prevent the form being closed unless you manually set the
reallyCloseflag totruebefore closing the form.You should make sure to close the form properly after you’ve finished using it.
Another option might be to decouple the data you need to retrieve from Form1 from the form itself.