Disable Close Button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolminded
    New Member
    • Mar 2007
    • 137

    #1

    Disable Close Button

    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
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by coolminded
    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.

    Comment

    • ansumansahu
      New Member
      • Mar 2007
      • 149

      #3
      Originally posted by coolminded
      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.developerfu sion.co.uk/show/72/8/

      -ansuman sahu

      Comment

      • ansumansahu
        New Member
        • Mar 2007
        • 149

        #4
        Originally posted by coolminded
        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

        Comment

        • SanjuMtr
          New Member
          • Mar 2007
          • 47

          #5
          Originally posted by coolminded
          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
          Code:
          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()
             RemoveCloseMenuItem (Me.hwnd) ' this is a user define pocedure
          end sub
          'the actual procedure
          Public Sub RemoveCloseMenuItem(ByVal hwnd As Long)
              Const SC_CLOSE = &HF060
              'Const SC_MINIMIZE = &HF060
              Const MF_BYCOMMAND = 0
              'Const MF_BYCOMMAND1 = 1
              Dim hMenu As Long
              'Dim hMenu1 As Long
              ' get the system menu's handle
              hMenu = GetSystemMenu(hwnd, 0)
              'hMenu1 = GetSystemMenu(hwnd, 1)
              ' remove the Close item
              RemoveMenu hMenu, SC_CLOSE, MF_BYCOMMAND
              'RemoveMenu hMenu1, SC_MINIMIZE, MF_BYCOMMAND1
          End Sub
          Try it.I am also waiting for your response.
          try it also in vb.net (I am no try it yet).Good luck.

          Comment

          Working...