private void Preferences_FormClosing(object sender, FormClosingEventArgs e) { if (this.cancelClose) { // Prevent the form from being automatically closed if it failed validation e.Cancel = true; this.cancelClose = false; } }