Form Closing on X C#
After an immense amount of reasearch I am still no closer to a solution.
I have a simple app, 2 forms .NETv3.5 C#.
The application loads the f开发者_Go百科irst form, i press 'X' on the windows bar.
The application hides the form and continues to run without exiting the application even though the only form loaded is closed.
The main form Closing method does not get called when the X is pressed because the form is hidden when the x is pressed. Form.Deactivated is called but not Form.Closing.
How can i catch the the even when the X is pressed ? (Then I can implement Application.Exit())
Check if you have timer or thread that is running. If so stop those.
I guess in Program.cs, you call Application.Run
passing the main form as parameter. If so, the app won't exit until the main form closes.
To catch the event when X button is pressed, add event handler to secondary form's Closed
event, not the main form's. In that event, call main form's Close
method (or Application.Exit
).
精彩评论