private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { if (MessageBox.Show(this, "Do you really want to close?", "Close?", MessageBoxButtons.YesNo) == DialogResult.No) { e.Cancel = true; } } }
Therefore, when I want to close the application by clicking the close button, the message box is displayed as it should, then I selected no. Then the line e.Cancel = true is executed and the form is not closed.
Now the fact is that after this, if I close the application from the task manager, the reason for closing is UserClosing !!! What for? Shouldn't be TaskManagerClosing?
source share