views:

248

answers:

2

In my application... to navigate between winforms what i do is that i make an object of the form that needs to be shown and i use

Register reg = new Register()
reg.show();

this thing has two problems

  • if i do it with a button, more than one instance of same form could be opened.
  • if i close through which the instance was created, the child form stays opend.

what is the solution....

A: 

Take a look at this code sample from MSDN code gallery. If you go through the code in detail, you should be good to go

Perpetualcoder
the two probl;ems i have listed, the sample has the samp problem#1. And for problem#2 that seems to be solved in the sample. try making another child from a child its not solved. not helpfull buddy
Junaid Saeed
If you are going to blindly follow it then there is no use. Downvoting me for this reason is simply rude, totally uncalled for
Perpetualcoder
+1  A: 

have the child form take as a parameter the parent form:

Form2 f2 = new Form2(this);
this.hide();
f2.show();

then when you wish to close the new form you just close it and show the parent form again.

code from Form2:

private Form Fatherform;

Form2(Form father){
   Fatherform = father;
}

Form2_closeevent( ... )
{
    if(Fatherform != null)
       Fatherform.show();
ThanosPapathanasiou
no no man... the problem is that when i close the fatherform.. all the child forms should close...
Junaid Saeed
ah, my bad. then you want Application.Exit();
ThanosPapathanasiou
no. no... i just wanted to close on child... hey i found the solution..i am not going to create any instances in a button click event and on closing of that form i will close all the child forms.
Junaid Saeed
thans for the answer "Form2_closeevent" got me to the solution
Junaid Saeed