Click here to Skip to main content
15,886,718 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
My idea is..
I have 2 forms.
Firstly i will run Form1.It consist of a button.
When I press on the button, Form1 will hide and Form2 will appear.
And then when I press the CancelButton from Form2, I wanna exit form application (ie. both Form1 and Form2 are closed.)But yet applicatoin not exit. Form2 closed and Form1 remain on memory. Would u help me any suggestion please??????????????
Posted

Try the Application.Exit[^] method.

An alternative is to hide Form1 when you display Form2, but use ShowDialog rather than the Show method. You can then use Close on Form1 when Form2 closes.

Or you could add an event handler in Form1 for the Form2 instance FormClosed event, and close Form1.
 
Share this answer
 
Comments
DaveyM69 10-Oct-11 13:25pm    
Gets my 5! I prefer the second option everytime.
To stops all running message loops on all threads and closes all windows of the application you should use Application.Exit() function. I am suspecting you are using this.Close() function. lets take some difference between Application.Exit() and Close() function.Take a look there-MSDN-[this.close() Vs Application.Exit()][^] for more references
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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