how to open 2nd form from 1st and close the 1st one simultaneously

dreskei's Avatar, Join Date: Oct 2010
Go4Expert Member
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
0
dotNet Zombie's Avatar, Join Date: Aug 2010
Go4Expert Member
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();
}
blackrubybarb, shabbir likes this
0
dreskei's Avatar, Join Date: Oct 2010
Go4Expert Member
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
0
blackrubybarb's Avatar, Join Date: Oct 2010
Light Poster
try this
private void REGISTERbtn_Click(object sender, EventArgs e)
{
details obj=new details();
obj.show();
this.Dispose();
}
0
dotNet Zombie's Avatar, Join Date: Aug 2010
Go4Expert Member
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()
0
dreskei's Avatar, Join Date: Oct 2010
Go4Expert Member
it worked....thnx a lot!!