Welcome to AddressOf.com Sign in | Join | Help

Windows Forms - Disable the Close Button

I've seen it asked over and over, “How do I disable the close button without having to remove the system menu, minimize and maximize buttons?”.  I've created an article that shows two seperate methods for doing so.  The first is the one that seems to be very popular and rehashed several times in various messageboards.  However, although it disables the actual button, it removes the Close menu item, which in my mind isn't the proper way of doing this.  I show a second method that follows the example shown in the Platform SDK documentation for actually disabling the Close menu item.  Also, it requires a lot less interop calls (two methods as opposed to five or more depending on if you will be trying to show the error messages).

[Article] Windows Forms - Disable the Close Button

Published Friday, October 31, 2003 3:44 AM by CorySmith
Filed under: , ,


# Need to disable\enable a Form's Close button

Thursday, June 17, 2004 3:14 PM by Greg Robinson's Blog

# re: Windows Forms - Disable the Close Button

Tuesday, September 28, 2004 6:57 AM by Naveed:navshah@msn.com
Here is the challenge. I hope you would have fed up solving this issue for many times. :-)

I need something more interesting. When my program run.... I need to disable system menu of all running applications....

Infact I want to distribute a (.chm) Help file. I couldn't put it into VB properly and will have to use OLE with a third-class method. I want to disable "Jump to URL" from its system menu. I am not in fact a programmer. But I will appreciate a lot if you can help me...

Best Regards,

# re: Windows Forms - Disable the Close Button

Thursday, December 9, 2004 12:34 PM by porchfan

this worked form me.

I have a multi form project and I only wanted to close a particluar form from the main form.

# re: Windows Forms - Disable the Close Button

Thursday, March 17, 2005 5:11 PM by Ujwal Wadhawan
this is worked for me as well. I tried many codes but this one did the trick without any hassels. Thanks

# re: Windows Forms - Disable the Close Button

Monday, July 4, 2005 5:16 PM by Punkstar
I am using VB Express 2005, and I get this error...

'hwnd' is not a member of 'System.Windows.Forms.Form'.

Any ideas?

# re: Windows Forms - Disable the Close Button

Friday, July 28, 2006 3:55 AM by vani
How to disable the close button in windows form without writing a new class, may be by changing some property or including a method in the same form

# re: Windows Forms - Disable the Close Button

Sunday, August 27, 2006 8:31 AM by Shayne
Ok, I got the same error as punkstar. Funny thing is, I am running the same version of VB. I wonder if it has to do with that. If so, is there any other way to remove/disable the close button?
Anonymous comments are disabled