How to know user has clicked “X” or the “Close” button?

前端 未结 12 1054
野性不改
野性不改 2020-11-27 12:19

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

12条回答
  •  悲哀的现实
    2020-11-27 13:13

    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();
        }
    

提交回复
热议问题