Change the action when you click the close window button

I want the x button in the title bar to close the entire application, not the current form. How to do it?

+4
source share
2 answers

Attach an event handler for the FormClosed event on the form and call Application.Exit() . For instance:

 private void Form2_FormClosed(object sender, FormClosedEventArgs e) { Application.Exit(); } 
+4
source

@rsbarro is right, however I want to be more specific.

 private void Form_FormClosed(object sender, FormClosingEventArgs e) { // if close button clicked, not the computer is being shutdown or anyother reason if (e.CloseReason == CloseReason.UserClosing) { Application.Exit(); } } 
+2
source

Source: https://habr.com/ru/post/1343552/


All Articles