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
if (this.DialogResult == DialogResult.Cancel) { } else { switch (e.CloseReason) { case CloseReason.UserClosing: e.Cancel = true; break; } }
if condition will execute when user clicks 'X' or close button on form. The else can be used when user clicks Alt+f4 for any other purpose