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

Go4Expert Member
23Oct2010,00:35   #1
dreskei's Avatar
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
Go4Expert Member
26Oct2010,01:12   #2
dotNet Zombie's Avatar
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
Go4Expert Member
30Oct2010,00:34   #3
dreskei's Avatar
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
Light Poster
30Oct2010,12:10   #4
blackrubybarb's Avatar
try this
private void REGISTERbtn_Click(object sender, EventArgs e)
{
details obj=new details();
obj.show();
this.Dispose();
}
Go4Expert Member
1Nov2010,20:43   #5
dotNet Zombie's Avatar
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()
Go4Expert Member
14Nov2010,10:05   #6
dreskei's Avatar
it worked....thnx a lot!!