Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have login form and Main form.
After Login i get opened main form on that there is cancel button of control box.
When click Cancel Button of Control box of Main form it close only Main form not the whole application.
How to close Whole application on Clicking Cancel Button of Main form of Control box.
Posted
Comments
Member 2954534 30-Oct-12 4:08am    
What exactly do you mean by "Control box oy Main form"? Is it another dialog with a cancel button? Or is the cancel button a child of the Main form? Is the Main form opened as a dialog with your button set as its cancel button?

Hi,

You can close the application using the following way.

C#
private void frmMainMDI_FormClosing(Object sender, FormClosingEventArgs e)
       {
          Application.Exit();

       }
 
Share this answer
 
Comments
OriginalGriff 30-Oct-12 4:20am    
That is not necessarily a good idea - it does not allow the form to be re-used in another application.
It is better for the app to be closed by the normal methods.
VIPR@T 30-Oct-12 4:25am    
ok thanks ...
It depends on how you are doing this.
If you are opening the login form from the Main method, and on sucessfull login you are hiding the login form and showing the main form, then it depends on how you are showing it:

If you use ShowDialog, then just add a Close to the login form immediately after the ShowDialog call.
If you are using Show, then add a handler to the main form FormClosed event and call Close from there.

If you are doing something else, then we need to know what, as we can't see your screen, access your HDD, or read your mind. We can only work with what you tell us! :laugh:
 
Share this answer
 
Comments
SamWakchaure 30-Oct-12 4:06am    
i am hiding Login form and showing Main form.
OriginalGriff 30-Oct-12 4:18am    
Then use the appropriate method as above.

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