how to disable close button in a form?

chidambaram

Well-known member
Joined
Dec 27, 2007
Messages
62
Location
Chennai,India
Programming Experience
Beginner
hi everyone,

I want to disable a close button(X) in a form. In my form i need only minimize button and not close button and maximize button.

I set the maximize button property to false. Maximize button disables.

If i set the ControlBox property to false, all three button are not visible.

I need only Minimize button.

How can i do this?

Thanks in advance
 
On the form's propreties panel, set the following: MaximizeBox = false, MinimizeBox = false, ControlBox = false.
If you still want the title to appear, type something in to it, or leave it blank the title will go away.
 
jmcilhinney said:
SystemMenuManager class - A helper class that you can add an instance of to a form and remove the Move item from the system menu, which renders the form immoveable by the user, and/or disable or remove the Close item, which also disables the Close button on the title bar. When the Close item is disabled or removed the Alt+F4 key combination is also disabled. To use this class just add a single line of code similar to this to your form:
VB.NET:
Private myMenuManager As New SystemMenuManager(Me, False, SystemMenuManager.MenuItemState.Greyed)

Note that it does not affect any other items on the system menu as these should be accessed through properties of the form itself. Also, the Move item can only be removed as disabling it or greying it out seem to have no effect.

EDIT: I've taken the code from post #39 and incorporated it into a class that I've attached to this post. You can use this class to make your form immovable like so:

VB.NET:
Private immobiliser As New FormImmobiliser(Me)

http://www.vbforums.com/showthread.php?t=351533
 
Back
Top