The most straightforward way to do it is to override the behavior of the OnClosing method on the Form. Basically, this method passes an argument to the active control to see if it validates, and the Cancel flag on the argument is set accordingly. By overriding the value set on that flag, you can always allow the form to close:
protected override void OnClosing(CancelEventArgs e)
// Let the default behavior to happen.
// Do not allow cancellation of the close operation.
e.Cancel = false;
Dig Deeper on WinForms development
Related Q&A from Daniel Cazzulino
Here Daniel Cazzulino explains how to load a DSL (domain specific language) domain model instance file programmatically. This requires the .NET type ... Continue Reading
Here we offer a glimpse at 12 of .NET development expert Danny Cazzulino's top ASP.NET questions and answers. Continue Reading
C# developers should NOT be modifying InitializeComponent method in the code-behind (or any of the variable definitions) by hand. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.