Results 1 to 11 of 11

Thread: [RESOLVED] How to disable Close and Maximize Buttons?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Philippines
    Posts
    139

    Resolved [RESOLVED] How to disable Close and Maximize Buttons?

    how to do this one?

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: How to disable Close and Maximize Buttons?

    One way is to take them off compeltly by setting controlbox = false in the form properties.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Philippines
    Posts
    139

    Re: How to disable Close and Maximize Buttons?

    that would include the minimize button.. i jaz want to disable a close or a maximize button..

  4. #4
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: How to disable Close and Maximize Buttons?

    Here is a way to disable Close Button ... Put this into a Module:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetSystemMenu Lib "user32" _
    4.     (ByVal hwnd As Long, _
    5.      ByVal bRevert As Long) As Long
    6.  
    7. Private Declare Function RemoveMenu Lib "user32" _
    8.     (ByVal hMenu As Long, _
    9.      ByVal nPosition As Long, _
    10.      ByVal wFlags As Long) As Long
    11.      
    12. Private Const MF_BYPOSITION = &H400&
    13.  
    14. Public Function DisableCloseButton(frm As Form) As Boolean
    15.  
    16. 'PURPOSE: Removes X button from a form
    17. 'EXAMPLE: DisableCloseButton Me
    18. 'RETURNS: True if successful, false otherwise
    19. 'NOTES:   Also removes Exit Item from
    20. '         Control Box Menu
    21.  
    22.  
    23.     Dim lHndSysMenu As Long
    24.     Dim lAns1 As Long, lAns2 As Long
    25.    
    26.    
    27.     lHndSysMenu = GetSystemMenu(frm.hwnd, 0)
    28.  
    29.     'remove close button
    30.     lAns1 = RemoveMenu(lHndSysMenu, 6, MF_BYPOSITION)
    31.  
    32.    'Remove seperator bar
    33.     lAns2 = RemoveMenu(lHndSysMenu, 5, MF_BYPOSITION)
    34.    
    35.     'Return True if both calls were successful
    36.     DisableCloseButton = (lAns1 <> 0 And lAns2 <> 0)
    37.  
    38. End Function

    Then put this in Form_Load event:
    VB Code:
    1. DisableCloseButton Me

    If you want to disable Maximize Button just set "MaxButton = False" in the form properties
    Last edited by TheKill3r; Jan 8th, 2009 at 06:01 AM.

  5. #5
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: How to disable Close and Maximize Buttons?

    Try:

    in form Property ==>> Maxbutton = False

    and

    Code:
    Private Sub Form_Unload(Cancel As Integer)
    Cancel = 1
    End Sub
    "More Heads are Better than One"

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Philippines
    Posts
    139

    Re: How to disable Close and Maximize Buttons?

    thanx... it works well.. :-)

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to disable Close and Maximize Buttons?

    If you did this, you would need Task Manager to close the application.
    Quote Originally Posted by jp26198926
    Code:
    Private Sub Form_Unload(Cancel As Integer)
    Cancel = 1
    End Sub

  8. #8
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to disable Close and Maximize Buttons?

    Disable as in don't allow the user to close the form or for what other reason?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Philippines
    Posts
    139

    Re: How to disable Close and Maximize Buttons?

    Quote Originally Posted by dee-u
    Disable as in don't allow the user to close the form or for what other reason?
    A command button should be used when closing the form.

  10. #10
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to disable Close and Maximize Buttons?

    So have you solved your problem?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Philippines
    Posts
    139

    Re: How to disable Close and Maximize Buttons?

    yes...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width