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

前端 未结 12 1058
野性不改
野性不改 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:15

    I've done something like this.

    private void Form_FormClosing(object sender, FormClosingEventArgs e)
        {
            if ((sender as Form).ActiveControl is Button)
            {
                //CloseButton
            }
            else
            {
                //The X has been clicked
            }
        }
    

提交回复
热议问题