Welcome to MSDN Blogs Sign in | Join | Help

WinForms: Disabling the close button

What is desired

You do not want the user to be able to click on the Close button (the little "x" in the upper right).

Method #1: The ControlBox property

The WinForm ControlBox property is a good place to start, but it shows or hides the entire control box. That means it either shows or hides all three buttons. That isn't useful because one maywant the minimize and maximize buttons to work or because one may want those buttons to appear for visual consistency.

Method #2: Disabling the Close button directly

This thread on microsoft.public.dotnet.framework has a solution

The result:
- the control box is still visible (min, max, close)
- the close button will appear disabled
- clicking on the close button will not do anything

[Update on 2005-11-25, a clarification in reply to a comment]
This technique does correctly show the close button as disabled. It does not merely disable the *clickability*, it also correctly alters the appearance of the close button.

Published Sunday, October 30, 2005 12:33 PM by saveenr

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: WinForms: Disabling the close button

One user there commented, "This will disable its functionality, but the button will still appear enabled." Is that they case? If so, this is not a very good solution.
Sunday, October 30, 2005 3:46 PM by Tom

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker