How to disable 'Close box' in upper right of form

D

dbuchanan

It's easy to disable the Minimizebox and Maximizebox because they are
members of the form, but how do I disable the Closebox or whatever it
is called???


(Why are some things so hard to find out?) Why isn't there a "See Also"
topic for this. Why isn't there a named member for this?

Thank you,
dbuchanan
 
G

Guest

Set the Form's "ControlBox" Property to False or you can trap the closing
from the control box by overriding the WndProc Method


<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub WndProc(ByRef m As Message)
Dim SC_Close As Integer = &HF060
Dim WM_SysCommand As Integer = &H112
Select Case m.Msg
Case &H112 'WM_SYSCOMMAND
' The WM_ACTIVATEAPP message occurs when the application
' becomes the active application or becomes inactive.
Select Case m.WParam.ToInt32
Case &HF060 'SC_Close 'User clicked on "X"
'Do something if you want then exit sub without
passing the Message on to MyBase...this will stop the form from firing the
close event
Exit Sub
End If
End Select
End Select
MyBase.WndProc(m)
End Sub
 
D

dbuchanan

Hi Dennis,

If I set the ControlBox to false then I lose the Minimizebox and the
Maximizebox, which I want to keep.

Thank you for sharing your work-around to the absence of a way to
disable or individually hide the closebox button. It achieves one goal
- not allowing the user to close the form using that button. But it
misses the other goal by still displaying as if it is an enabled
control.

I am disappointed that because Microsoft didn't give us control over
this we have to violate the Windows standard of displaying all controls
that don't work as 'disabled' or 'grayed out'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top