You can override OnFormClosing to do this.
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.WindowsShutDown) return;
// DO WHATEVER HERE
}
solved How to override closing control in Windows Form c#