PDA

Click to See Complete Forum and Search --> : Disable Restore/Maximize...


Psyrus
Jul 28th, 2000, 05:58 PM
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?

Jul 28th, 2000, 07:17 PM
'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

Psyrus
Jul 28th, 2000, 09:06 PM
Thanks Matthew.

Jul 29th, 2000, 10:52 AM
It would better to store the values in variables rather than Labels.

Jul 29th, 2000, 03:23 PM
Here is another solution. Unlike the above method, this one will not show a "ghost" of the Form when you resize it.


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]

Jul 29th, 2000, 03:54 PM
Hehe Megatron, always have something more advanced :p.

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.

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]

Jul 29th, 2000, 04:17 PM
I usually prefer to use Error Handling as a last resort. Instead, here is a work around.


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 ;-)

Psyrus
Jul 29th, 2000, 08:45 PM
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.