Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   how to open 2nd form from 1st and close the 1st one simultaneously (http://www.go4expert.com/forums/2nd-form-1st-close-1st-simultaneously-t23648/)

dreskei 23Oct2010 00:35

how to open 2nd form from 1st and close the 1st one simultaneously
 
i have two window application forms form1-registeruser.cs
form2-details.cs
on clicking REGISTER button on form1,form2 is opened
but form1 is still there .....i am not getting how to close form1 with form2 still open
my code was as follows
private void REGISTERbtn_Click(object sender, EventArgs e)
{
details obj=new details();
obj.show();
close();
}
but this code closes both the forms ,form2 appear just for a second

dotNet Zombie 26Oct2010 01:12

Re: how to open 2nd form from 1st and close the 1st one simultaneously
 
If registerUser form is the form called from Program.cs, then it'll exit the application as soon as it closes.

Instead, just hide it.

private void REGISTERbtn_Click(object sender, EventArgs e)
{
details obj=new details();
obj.show();
this.Hide();
}

dreskei 30Oct2010 00:34

Re: how to open 2nd form from 1st and close the 1st one simultaneously
 
but this does not close the form ,it hides it....and then again when i run the application....it shows the error coz the application is still not completely closed....the form was only hidden not closed...although we cn continue neglecting that error

blackrubybarb 30Oct2010 12:10

Re: how to open 2nd form from 1st and close the 1st one simultaneously
 
try this
private void REGISTERbtn_Click(object sender, EventArgs e)
{
details obj=new details();
obj.show();
this.Dispose();
}

dotNet Zombie 1Nov2010 20:43

Re: how to open 2nd form from 1st and close the 1st one simultaneously
 
the dispose method will do the same thing as the Close method.

If you wanted to close the Application when there is a hidden form open, just set up a Form Closing Event that calls this Method: Application.Exit()

dreskei 14Nov2010 10:05

Re: how to open 2nd form from 1st and close the 1st one simultaneously
 
it worked....thnx a lot!!


All times are GMT +5.5. The time now is 18:56.