In MSDN I found CloseReason.UserClosing to know that the user had decided to close the form but I guess it is the same for both clicking the X button or clickin
CloseReason.UserClosing
It determines when to close the application if a form is closed (if your application is not attached to a specific form).
private void MyForm_FormClosed(object sender, FormClosedEventArgs e) { if (Application.OpenForms.Count == 0) Application.Exit(); }