Results 1 to 8 of 8

Thread: Disable Restore/Maximize...

  1. #1

    Thread Starter
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    How can I stop a user from resizing a form but still give them the ability to Minimize and Close it? I have a seen this done before where the Restore/Maximize on the form was disabled but Minimize and Close where still there. I do not want to change the BorderStyle of the form. Is there a way to do this through the API for each form in my program?



    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  2. #2
    Guest
    Code:
    'Needed:  2 labels, set the MaxButton property to false.
    
    Private Sub Form_Load()
    Label1.caption = Me.Height
    Label2.caption = Me.Width
    End Sub
    
    Private Sub Form_Resize()
    On Error Resume Next
    Me.Height = Label1.caption
    Me.Width = Label2.caption
    End Sub

  3. #3

    Thread Starter
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Thanks Matthew.


    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  4. #4
    Guest
    It would better to store the values in variables rather than Labels.

  5. #5
    Guest
    Here is another solution. Unlike the above method, this one will not show a "ghost" of the Form when you resize it.

    Code:
    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
    Dim LockWindow As Boolean
    Dim iWidth As Integer
    Dim iHeight As Integer
    
    Private Sub Form_Load()
    
        'Save the initial dimensions
        iWidth = Me.Width
        iHeight = Me.Height
        
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        'Unlock the Window when the Mouse is moved over it
        LockWindowUpdate 0&
    
    End Sub
    
    Private Sub Form_Resize()
    
        Static FirstLoad
        
        'If this is the First time the Window is loading then don't lock it
        If FirstLoad = False Then
            FirstLoad = True
            LockWindow = True
            Exit Sub
        End If
        
        'Lock the Window when the User tries to resize it
        If LockWindow = True Then
            'Restore the dimensions
            Me.Width = iWidth
            Me.Height = iHeight
            LockWindowUpdate Me.hWnd
        End If
    
    End Sub
    [Edited by Megatron on 07-29-2000 at 04:26 PM]

  6. #6
    Guest
    Hehe Megatron, always have something more advanced .

    But don't forget the On Error Resume Next so when the form is minimized or maximized, it won't give you the error.

    And oh yeah, you don't need to labels. Just dim it.

    Code:
    Form_Declarations:
    Dim iWidth As Integer
    Dim iHeight As Integer
    
    Private Sub Form_Load()
    iWidth = Me.Width
    iHeight = Me.Height
    End Sub
    
    Private Sub Form_Resize()
    On Error Resume Next
    Me.Height = iHeight
    Me.Width = iWidth
    End Sub
    Thanks Megatron for pointing that out. Labels take up resources...not a lot, but it'd take less memory to Dim it instead.

    [Edited by Matthew Gates on 07-29-2000 at 05:04 PM]

  7. #7
    Guest
    I usually prefer to use Error Handling as a last resort. Instead, here is a work around.

    Code:
    Private Sub Form_Resize()
    
        If Me.WindowState <> vbMinimized Then
            Static FirstLoad
            
            'If this is the First time the Window is loading then don't lock it
            If FirstLoad = False Then
                FirstLoad = True
                LockWindow = True
                Exit Sub
            End If
            
            'Lock the Window when the User tries to resize it
            If LockWindow = True Then
                'Restore the dimensions
                Me.Width = iWidth
                Me.Height = iHeight
                LockWindowUpdate Me.hWnd
            End If
        Else: FirstLoad = False
        End If
        
    End Sub
    Just dim it
    Declare it ;-)


  8. #8

    Thread Starter
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Thanks again.

    What I did was use two public CONST variables in a .bas file, MHEIGHT and MWIDTH. All of the forms I want to prevent the resize are of the same height and width, so I just use these constants when necessary.



    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

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