By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,591 Members | 650 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,591 IT Pros & Developers. It's quick & easy.

Disable Close Button

100+
P: 138
hi all,
can the close button on the title bar of the form be disabled so that the user can't close the form.
thanx
Apr 13 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
hi all,
can the close button on the title bar of the form be disabled so that the user can't close the form.
Yes. If it's VB6, you set the form's ControlBox property to False.

In Vb.Net, I have no idea.
Apr 13 '07 #2

100+
P: 149
hi all,
can the close button on the title bar of the form be disabled so that the user can't close the form.
thanx
You can check this link and see if it helps for disabling the close button.

http://www.developerfusion.co.uk/show/72/8/

-ansuman sahu
Apr 13 '07 #3

100+
P: 149
hi all,
can the close button on the title bar of the form be disabled so that the user can't close the form.
thanx
Also this is another link see if it helps you out

http://www.freevbcode.com/ShowCode.Asp?ID=2448

-ansuman sahu
Apr 13 '07 #4

P: 47
hi all,
can the close button on the title bar of the form be disabled so that the user can't close the form.
thanx
yes you Can do it in Two way.1) the Killer42 already told you & another
by Calling Two API
I Just Giving you the sample Code how to implement it. try it
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
  3.                          ByVal bRevert As Long) As Long
  4. Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, _
  5.                          ByVal nPosition As Long, ByVal wFlags As Long) As Long
  6.  
  7. Private Sub Form_Load()
  8.    RemoveCloseMenuItem (Me.hwnd) ' this is a user define pocedure
  9. end sub
  10. 'the actual procedure
  11. Public Sub RemoveCloseMenuItem(ByVal hwnd As Long)
  12.     Const SC_CLOSE = &HF060
  13.     'Const SC_MINIMIZE = &HF060
  14.     Const MF_BYCOMMAND = 0
  15.     'Const MF_BYCOMMAND1 = 1
  16.     Dim hMenu As Long
  17.     'Dim hMenu1 As Long
  18.     ' get the system menu's handle
  19.     hMenu = GetSystemMenu(hwnd, 0)
  20.     'hMenu1 = GetSystemMenu(hwnd, 1)
  21.     ' remove the Close item
  22.     RemoveMenu hMenu, SC_CLOSE, MF_BYCOMMAND
  23.     'RemoveMenu hMenu1, SC_MINIMIZE, MF_BYCOMMAND1
  24. End Sub
  25.  
Try it.I am also waiting for your response.
try it also in vb.net (I am no try it yet).Good luck.
Apr 13 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.