Click here to Skip to main content
16,016,744 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
I have 2 forms in a windows application - LogonForm and ProcessForm. The Logon Form is setup as the "Startup Object" for the project. Upon successful logon, I have the below code to transfer the control from LogonForm to ProcessForm and close the LogonForm (only).

//Instantiate ProcessForm and Show ProcessForm
MyProcessForm = new ProcessForm(InputData);
MyProcessForm.Show();

//Close the Logon Form
this.Close();

This code actually closes the entire application without showing the ProcessForm.

Now, if I change this.Close() to this.Hide(), the ProcessForm opens, but when I close the ProcessForm, I can see the application still running as the "LogonForm" is still in the hidden state.

When I close the ProcessForm, I have to close the entire application. Can you please help me with how to do it? Thanks in advance for your help
Posted

Hi,

Yes the first form is the main form, closing it ends the app.
If you are working in C#, have a look at Main() in program.cs; you'll see your first form is treated differently, it is passed to Application.Run
You could adapt program.cs to have two Application.Run statements, one with the logon form, the next with your real main form.

OTOH Application.Exit() should terminate your app no matter what.

:)

 
Share this answer
 
When the main form closes, it will stop the message loop and your application will end. You need to change the main method and do something like,
int main()<br />{<br />     // show the login form here. <br />     if(loginValidated)<br />     {<br />         // starts the application message loop<br />         Application.Run(new ProcessForm());<br />         /* .... */<br />     }<br />}


 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900