Click here to Skip to main content
11,428,876 members (61,648 online)
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Disable the Close box on a form

, 1 Feb 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Brian Pendleton
Software Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralI Agree with the Griff here much easier and less confusing f... Pin
charles henington27-Jun-11 13:00
membercharles henington27-Jun-11 13:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150428.2 | Last Updated 2 Feb 2010
Article Copyright 2010 by Brian Pendleton
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid