Click here to Skip to main content
12,250,257 members (50,636 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

2.6K views
1 bookmarked
Posted

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

You may also be interested in...

Comments and Discussions

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

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web01 | 2.8.160426.1 | Last Updated 2 Feb 2010
Article Copyright 2010 by Brian Pendleton
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid