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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Close Button 4

Status
Not open for further replies.

jonatan

Programmer
Mar 24, 2003
14
BR
Is there anyway to disable the X button (close button) in the top of the form? I want to avoid that the form be closed this way.

Tks

---
Jonatan Schroeder
Medisoft Ltda. - Brazil
System Development
Project Coordination
 
If you do not need the Minimise and Maximise buttons either then you can change the CONTROLBOX property of the form to False.

Greg Palmer

----------------------------------------
Any feed back is appreciated.
 
The .controlbox property will remove all the buttons on the right of the title bar, not just disable them.

Thanks and Good Luck!

zemp
 
If you want to disable just the x button the check out
thread222-523899


Greg Palmer

----------------------------------------
Any feed back is appreciated.
 
Also the .controlbox is not available at runtime.

Here is code that will disable the 'x'

Code:
Const MF_BYPOSITION = &H400 
Private Declare Function GetSystemMenu Lib "User32" _ 
(ByVal hWnd As Long, ByVal bRevert _ 
As Long) As Long 
Private Declare Function RemoveMenu Lib "User32" _ 
(ByVal hMenu As Long, ByVal nPosition _ 
As Long, ByVal wFlags As Long) As Long 

Private Sub Form_Load() 
RemoveMenu GetSystemMenu(Me.hWnd, 0), 6, MF_BYPOSITION 
End Sub


Thanks and Good Luck!

zemp
 
For supplying so many links to really useful code, you deserve a star!

Business and Data Analyst
Database & Web Applications
International Applications Development
VB,VBA,ASP,SQL,Java,Pascal,ADA,SSADM,UML
Interested parties please email: seanunderwood1@hotmail.com

 
I second that.

jgjge3.gif
[tt]"Very funny, Scotty... Now Beam down my clothes."[/tt]
 
I third it! I've been looking for just this code for yonks!! You are a star zemp!
 
Thanks for the kind words! Glad to be of help.

Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
JAG14

I lov you tag!!! Its the only one thats ever made me laugh!!! (sorry off topic)

Business and Data Analyst
Database & Web Applications
International Applications Development
VB,VBA,ASP,SQL,Java,Pascal,ADA,SSADM,UML
Interested parties please email: seanunderwood1@hotmail.com

 
You can also use this method, which will enable you to call other functions from the Form_Unload event, try this in that event...

Private Sub Form_Unload(Cancel As Integer)
MsgBox "Ha ha, wont close", vbOKOnly, "Help"
Cancel = 1
End Sub
 
Here's a better example..

Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Really want to close?", vbYesNo, "Close App?") = vbNo Then
Cancel = 1
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top