Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can close a 1st form without closing the full application? [duplicate]

Tags:

c#

Possible Duplicate:
How can I close a login form and show the main form without my application closing?

How i can close a 1st form with out closing full the application?
C#. as a example if my 1st form is logging form after enter username and password if they are correct that form should be close and other form need to be open.

I tried this.close() but my full application is exiting :(. After that I tried this.Hide() it works but my form is still running just hidden from UI.

ty

like image 699
Rajika Nanayakkara Avatar asked Nov 15 '25 13:11

Rajika Nanayakkara


1 Answers

It is actually quite simple. On your Program.cs Main static method use the following code to launch your LoginForm.

var myLoginForm = new LoginForm();
myLoginForm.Show();
Application.Run();

Then from your LoginForm, simply remember to launch your next Form before closing it like this:

var myNextForm = new NextForm();
myNextForm .Show();

this.Close();

If you rather just want to close the application after login fails just do the following:

this.close();
Application.Exit();

Hope it helps!

like image 133
Reinaldo Avatar answered Nov 18 '25 07:11

Reinaldo