471,107 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,107 software developers and data experts.

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

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

Nov 21 '05 #1
3 5003
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.PermissionSetAttribut e(System.Security.Permissions.SecurityAction.Deman d, 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
--
Dennis in Houston
"dbuchanan" wrote:
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

Nov 21 '05 #2
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'.

--
dbuchanan

Nov 21 '05 #3
"dbuchanan" <db*********@hotmail.com> schrieb:
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???


<URL:http://dotnet.mvps.org/dotnet/code/windowsandforms/#NoClose>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mike Nooney | last post: by
5 posts views Thread by Stan Sainte-Rose | last post: by
7 posts views Thread by eye5600 | last post: by
5 posts views Thread by lord.zoltar | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.