Resizing Controls when resizing the form window

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good Morning everyone,
I was wondering, is there a method in Access 2003 that makes the controls on
form change its size when the form window is resized.(Minimzed, maximized,
manually resized...)
I have been infomed that the "OnResize" event will do the trick, but my
question is how can it be dome?
Cheers
 
The code to do this (In Access 97) is available in the "Access 97 Developer's
Handbook" (
www.amazon.com/Access-Developers-Handbook-Paul-Litwin/dp/0782119417)


In a Module:


Function adhResizeForm(frm As Form, ByVal fDoResize As Variant, _
rctOriginal As adhTypeRect)

' Called from the Resize event of forms.
' Attempt to resize the form and all its
' controls. Don't do anything if the
' current height of the form is 0, or if it's iconic.

' From Access 97 Developer's Handbook
' by Litwin, Getz, and Gilbert (Sybex)
' Copyright 1997. All rights reserved.

' In:
' frm: A reference to the form in question
' fDoResize: Yes/No (Actually do the resize, or just track the
information?)
' rctOriginal: the original coordinates
' Out:
' Nothing

Dim rctNew As adhTypeRect
Dim intWidth As Integer
Dim intHeight As Integer
Dim sglFactorX As Single
Dim sglFactorY As Single

On Error GoTo adhResizeWindowError
' Make sure the user hasn't sized this thing down
' to the nubs. If the client area is 0 height,
' it's time to call it quits.
adh_apiGetClientRect frm.hwnd, rctNew
intHeight = (rctNew.Y2 - rctNew.Y1)
If intHeight = 0 Or adh_apiIsIconic(frm.hwnd) Then
Exit Function
End If

' Now get the actual window height and width.
adh_apiGetWindowRect frm.hwnd, rctNew

' Get the current width and height.
intHeight = (rctNew.Y2 - rctNew.Y1)
intWidth = (rctNew.X2 - rctNew.X1)

' Calc the scaling factor, given the current
' height/width and the previous height/width.
' Could be that rctOriginal has not yet been
' initialized, so trap for that error.

sglFactorX = intWidth / (rctOriginal.X2 - rctOriginal.X1)
sglFactorY = intHeight / (rctOriginal.Y2 - rctOriginal.Y1)

sglFactorOK:
' Store away the current values for
' the next time through here.
With rctOriginal
.X1 = rctNew.X1
.X2 = rctNew.X2
.Y1 = rctNew.Y1
.Y2 = rctNew.Y2
End With
' If the ratios are 1, there's nothing to do.
If (sglFactorX <> 1) Or (sglFactorY <> 1) Then
' If you actually want to do some resizing, do it now.
If fDoResize Then
SetFormSize frm, sglFactorX, sglFactorY, rctNew, False
End If
End If

adhResizeWindowExit:
Exit Function

adhResizeWindowError:
If Err = adhcErrDivisionByZero Then
sglFactorX = 1
sglFactorY = 1
Resume sglFactorOK
Else
HandleError "adhResizeForm", Err.Number, Err.Description
Resume Next
End If
End Function

In the forms 'On Resize' property:

Private Sub Form_Resize()
On Error GoTo Form_Resize_Err
adhResizeForm Me, Me!chkEnableResize, rctOriginal
Form_Resize_Exit:
Exit Sub
Form_Resize_Err:
MsgBox Err.Description
Resume Form_Resize_Exit
Resume
End Sub

Ensure you have a checkbox called 'chkEnableResize' on your form.



This could be a starting point for your Access Version.

ZH
 
Back
Top