ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   form closing with the X (https://www.excelbanter.com/excel-programming/348692-form-closing-x.html)

raw[_15_]

form closing with the X
 

Hi

Is there a way to remove the X (Close button) at the top of the form
(just like the help button). This will make users only be able to close
the form with a cancel button (command button)

thanks


--
raw
------------------------------------------------------------------------
raw's Profile: http://www.excelforum.com/member.php...o&userid=28312
View this thread: http://www.excelforum.com/showthread...hreadid=495375


Bob Phillips[_6_]

form closing with the X
 
You don't need to remove it, you can trap it. Look up the QueryClose Event
in help.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"raw" wrote in message
...

Hi

Is there a way to remove the X (Close button) at the top of the form
(just like the help button). This will make users only be able to close
the form with a cancel button (command button)

thanks


--
raw
------------------------------------------------------------------------
raw's Profile:

http://www.excelforum.com/member.php...o&userid=28312
View this thread: http://www.excelforum.com/showthread...hreadid=495375




RB Smissaert

form closing with the X
 
I find it causes less confustion with the user to have the X button disabled
by the Windows API:


In a normal module have this:

Option Explicit
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Public Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Public Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) _
As Long

Sub DisableCloseButton(hwnd As Long)

Dim hMenu As Long
Dim menuItemCount As Long

hMenu = GetSystemMenu(hwnd, 0)

If hMenu Then
menuItemCount = GetMenuItemCount(hMenu)
RemoveMenu hMenu, _
menuItemCount - 1, _
MF_REMOVE Or MF_BYPOSITION
DrawMenuBar hwnd
End If

End Sub

Sub LoadForm()

Load UserForm1
UserForm1.Show

End Sub


In the form code have this:

Option Explicit

Private Sub UserForm_Activate()
DisableCloseButton GetActiveWindow()
End Sub


RBS


"raw" wrote in message
...

Hi

Is there a way to remove the X (Close button) at the top of the form
(just like the help button). This will make users only be able to close
the form with a cancel button (command button)

thanks


--
raw
------------------------------------------------------------------------
raw's Profile:
http://www.excelforum.com/member.php...o&userid=28312
View this thread: http://www.excelforum.com/showthread...hreadid=495375




All times are GMT +1. The time now is 05:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com