473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 5107
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alleg | last post by:
hi everyone I am new to VC++.NET, however, I have to implement this project in vc++.net. Here is the trouble I am facing. I wanna disable the red close button at the right upper corner of a...
2
by: Mike Nooney | last post by:
How do I disable the "X" in the upper right hand corner of my Web Page. This is not for a windows form, but rather a web application. What I really need is to stop the user from unloading the...
5
by: Stan Sainte-Rose | last post by:
Hi, Which event is called when the user click on the close window icon (X) ? I want, when he clicks on this icon, to display a message before closing the form. If he replys by No, I don't want to...
12
by: Mika M | last post by:
Customer wants the Close (X)-button of the forms top right corner to be Disabled or removed from Windows Form-application, which is made using VB.NET, but leave MinimizeBox and MaximizeBox. I...
7
by: eye5600 | last post by:
I have a procedure that creates a file, then generates a log report via Crystal. If the user closes the form after the file is created and before the log appears, the form closes, but (it appears...
2
by: ohadasor | last post by:
Hello, I have an MDI child, which I need to be opened as long as the mainframe is opened. The problem is that the user can close it using the X button in the form's top-right edge. How can I...
1
by: dan.c.roth | last post by:
oForm.Close() vs this.Close() in a modal dialog. oFrom.Close() calls Form.Dispose() but this.Close() ,say in the click event of the Form, does not. I can think of the reason for this but is...
5
by: lord.zoltar | last post by:
How can I prevent the big close button in the top of the window from closing the window? I want to have and "are you sure?" confirmation so the user must press "Yes" before the program ends. Right...
2
by: mahesh123 | last post by:
Hi, I had a small problem regarding the Right click of the Mouse button. ie when the form as Border Style= Fixed style, Control Box = False. these are the properties set to the form. and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.