Requires Free Membership to View
When you register, you'll begin receiving targeted emails from my team of award-winning writers. Our goal is to provide a unique online resource for developers, architects and development managers tasked with building and maintaining enterprise applications using Visual Basic, C# and the Microsoft .NET platform.
Hannah Smalltree, Editorial DirectorThe 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.
base.OnClosing(e);
// Do not allow cancellation of the close operation.
e.Cancel = false;
}
This was first published in March 2005