For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > April 2005 > How do I remove the 'X' on the top of the form?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How do I remove the 'X' on the top of the form?
winter

2005-04-11, 2:38 pm

I don't want my user's to use this X to exit from a program. Is there a way to remove it?

I'm sure this has been asked a million times plus 2....
Ken Halter

2005-04-11, 9:00 pm

"winter" <winter.1ncdtt@mail.codecomments.com> wrote in message
news:winter.1ncdtt@mail.codecomments.com...
>
> I don't want my user's to use this X to exit from a program. Is there a
> way to remove it?
>
> I'm sure this has been asked a million times plus 2....


actually, plus 3 <g>... anyway, imo, it's best to leave it there and just
"handle" it.
'============
Option Explicit

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
MsgBox "Use the Exit button instead!"
Cancel = True 'set Cancel = non zero value
End If
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub
'============

If that's not enough, you can set the ControlBox property of that form to
False (removes all buttons and the icon) or use the API to get rid of it all
together.

Killing the Form Close Menu and 'X' Button
http://vbnet.mvps.org/index.html?co...s/killclose.htm

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..


Ed

2005-04-12, 4:00 am

On Mon, 11 Apr 2005 14:38:33 -0500, winter
<winter.1ncdtt@mail.codecomments.com> wrote:

>
>I don't want my user's to use this X to exit from a program. Is there a
>way to remove it?
>
>I'm sure this has been asked a million times plus 2....


not my code, just saw it posted somewhere...
hth,
Ed


Private Declare Function DeleteMenu& _
Lib "user32" _
(ByVal hMenu&, ByVal nPosition&, ByVal wFlags&)

Private Declare Function GetSystemMenu& _
Lib "user32" _
(ByVal hwnd&, ByVal bRevert&)

Sub No_X()
Const SC_CLOSE& = &HF060&, MF_BYCOMMAND& = &H0&
DeleteMenu GetSystemMenu(Me.hwnd, False), SC_CLOSE, MF_BYCOMMAND
End Sub

Sub RemetX()
GetSystemMenu Me.hwnd, True
End Sub


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com