Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disabling close button (X) on form

Status
Not open for further replies.

tyedyejenn

Programmer
Jun 14, 2000
35
0
0
US
I want to disable the X (close button) on a form.&nbsp;&nbsp;I see in the properties for a form you can disable the min and max buttons but I only want to disable the X(close button)<br><br>Thanks Jenn
 
tyedyejenn,<br><br>I do not know of a way to disable the (X) button. But I do know how to cancel the Form_Unload(Cancel as Integer).<br><br>Change &quot;Cancel&quot; to a 1.<br><br>Ex:<br>Private Sub Form_Unload(Cancel as Integer)<br>&nbsp;&nbsp;&nbsp;&nbsp;If(bCondition = True) then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cancel = 1 ' Do not Close/Unload form<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;' Insert your Unload code here<br><br>End Sub<br><br>Note: The user would be able to press the (X) Button but it does not do anything.<br><br>good luck,<br><br>Leaf<br>
 
There is also the 'ControlBox' property, that makes up for the 'X' and the menu under the icon on the leftside. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Below is some code I found, but unfortunately I do not have record of the author. I just wanted to say that I did not write this. One drawback is that the close menu item is not disabled, but made invisible. The X is just disabled. I hope this helps you.<br><br><FONT FACE=monospace>Option Explicit<br><br>' Used to Remove the Close Button.<br><br>Const MAXIMIXE_BUTTON = &HFFFEFFFF<br>Const MINIMIZE_BUTTON = &HFFFDFFFF<br>Const MF_BYPOSITION = &H400<br><br>' Used when calling RemoveClose<br>Enum RemoveMenuEnum<br>&nbsp;&nbsp;&nbsp;&nbsp;rmMove = 1<br>&nbsp;&nbsp;&nbsp;&nbsp;rmSize = 2<br>&nbsp;&nbsp;&nbsp;&nbsp;rmMinimize = 3<br>&nbsp;&nbsp;&nbsp;&nbsp;rmMaximize = 4<br>&nbsp;&nbsp;&nbsp;&nbsp;rmClose = 6<br>End Enum<br><br>Private Declare Function GetSystemMenu Lib &quot;User32&quot; _<br>&nbsp;&nbsp;&nbsp;&nbsp;(ByVal hWnd As Long, ByVal bRevert As Long) As Long<br><br>Private Declare Function RemoveMenu Lib &quot;User32&quot; _<br>&nbsp;&nbsp;&nbsp;&nbsp;(ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long<br><br>Private Sub RemoveClose(ByVal hWNDForm As Long)<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim lSysMenu As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim lStyle&nbsp;&nbsp;&nbsp;As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;lSysMenu = GetSystemMenu(hWNDForm, 0&)<br>&nbsp;&nbsp;&nbsp;&nbsp;' Remove Close button<br>&nbsp;&nbsp;&nbsp;&nbsp;Call RemoveMenu(lSysMenu, rmClose, MF_BYPOSITION)<br>&nbsp;&nbsp;&nbsp;&nbsp;' Remove separator above it<br>&nbsp;&nbsp;&nbsp;&nbsp;Call RemoveMenu(lSysMenu, rmClose - 1, MF_BYPOSITION)<br>End Sub<br><br>Private Sub Form_Load()<br>&nbsp;&nbsp;&nbsp;&nbsp;RemoveClose hWnd<br>End Sub</font> <p>Phil Hunt<br><a href=mailto:philh@dqc.com>philh@dqc.com</a><br><a href= > </a><br>
 
hmm that looks interesting, if you find the author tell him thanks( maybe I can use it to make a flashing close button ) <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Hi,<br><br>all the above seem to complicated ... just make the &quot;controls&quot; property of the form &quot;False&quot; ... this will disable all min / max / close buttons on the form<br><br>regards -- clentin
 
From what I understand, tyedyejenn wants the Min and/or Max buttons to still exist, but the close button (X) to just be disabled. If you set ControlBox = False, none will not appear at all.<br><br>P.S. - the code above is not really that complex. It's just a couple API calls and some constants. <p>Phil Hunt<br><a href=mailto:philh@dqc.com>philh@dqc.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top