Click to See Complete Forum and Search --> : how to hide close option in form


sahilkhan
May 27th, 2001, 03:20 AM
how to hide close option in form I dont want end user to use x button

cksiow
May 27th, 2001, 06:24 AM
refer http://vblib.virtualave.net, there is a function called DisableXButton in vbSystem of the activeX DLL which might help

HTH

himakara
May 27th, 2001, 12:05 PM
ok all you got to do is there is a property in the properties window you should be able to fine aproperty called controllbox set it to false then those button will not be displayed play with the things in the properties window to find out more like minbutton, maxbutton

John G Duffy
May 27th, 2001, 02:52 PM
Set the Controlbox property to False to get rid of the Min,Max,CLose buttons. IF all you want to do is disable the Close button and leave Min and Maximize buttons available, use the following code in the following sample.
Add a command button to a form. Add a module to the project

'
' This is the Forms Code
'
option Explicit

private Sub Command1_Click()
Unload me
End Sub

private Sub Form_Load()

Dim hMenu as Long
Dim menuItemCount as Long

'Obtain the handle to the form's system menu
hMenu = GetSystemMenu(me.hwnd, 0)

If hMenu then

'Obtain the number of items in the menu
menuItemCount = GetMenuItemCount(hMenu)

'Remove the system menu Close menu item.
'The menu item is 0-based, so the last
'item on the menu is menuItemCount - 1
Call RemoveMenu(hMenu, menuItemCount - 1, _
MF_REMOVE Or MF_BYPOSITION)

'Remove the system menu separator line
Call RemoveMenu(hMenu, menuItemCount - 2, _
MF_REMOVE Or MF_BYPOSITION)

'Force a redraw of the menu. This
'refreshes the titlebar, dimming the X
Call DrawMenuBar(me.hwnd)

End If

End Sub
'--end block--'
'
' This is the Modules code
option Explicit

public Const MF_BYPOSITION = &H400
public Const MF_REMOVE = &H1000

public Declare Function DrawMenuBar Lib "user32" _
(byval hwnd as Long) as Long

public Declare Function GetMenuItemCount Lib "user32" _
(byval hMenu as Long) as Long

public 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 '--end block--'




John G