tags:

views:

51

answers:

2

Hey. When I say close, I do not speak of the method close(), but when a user hits the close button to the window. I have multiple forms, that show and hide depending on if the user is logged in or about to log in and so on. When the user finaly close one of the forms, I want them all to just exit. Now, when a user closes a form, the program is still running because there is a form in the background hiding.

How can I exit on close, I remember doing this in Java, thanks.

+6  A: 

Call the Application.Exit() method.

Bernard
Well yes, but how can I say that this is going to be called on close...
Johannes
Handle the Form.FormClosed() event.
Bernard
You can do it in the Form_Closing event handler.http://msdn.microsoft.com/en-us/library/system.windows.forms.form.closing.aspx
David Stratton
thanks, that worked
Johannes
A: 

Only call Application.Exit() if you know, that the rest of the application can close ungracefully. If other open forms need to do something in their FormClosing event, this wont get done. Using Application.Exit() is a "bad code smell" meaning that there is something wrong with your design.

Do centralized event handling that all forms subsribe to, so they can be notified when the application is closing. There are also plenty of other ways to handle this, Teh Googles knows :)

Paw Baltzersen