Disable the Close box on a form






3.56/5 (6 votes)
I could be missing the point here, but I believe you could also override the OnClosing event.protected override void OnClosing(CancelEventArgs e){ // allow default behavior.. base.OnClosing(e); // test for whatever... // on fail, e.Cancel = true; // set some...
I could be missing the point here, but I believe you could also override the OnClosing event.
protected override void OnClosing(CancelEventArgs e)
{
// allow default behavior..
base.OnClosing(e);
// test for whatever...
// on fail, e.Cancel = true;
// set some message, etc.
}
This method allows you to disable the action of closing, but leaves the "Close" button enabled - the user can then click it - but nothing happens. This may be confusing, unless you provide a MessageBox or similar to remind the user why he cannot close.