Link to home
Start Free TrialLog in
Avatar of lcleary
lcleary

asked on

Access Form Resize

How do I make an access form automatically resize itself depending on the screen resolution of the monitor? I think there is an API function to do this but I really don't know. Any ideas and samples would be very useful.
Avatar of BrianWren
BrianWren

I'm sure that you've thought of this, but who knows....?

Access has--built-in--Auto Resize, and Auto Center, which do this to a degree.  The form will be the right size to show all of its elements, and irrespective of resolution will be centered on the monitor.

Can you be more detailed about what you are trying to do?

Brian
Hi, lcleary, there's some graet utils for this and other things at www.fmsinc.com.  One is called Zoom.  Might be worthwhile to check it out.

good luck as usual...
Icleary:

Ken Getz's book (Access 97 Developers Handbook) covers the "scaling" of forms pretty good. It starts on page 465 under Screen Resolution. Some of the declares you will use include:

Public Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long


Public Declare Function GetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As RECT) As Long


etc. Good luck

Other way:
1. Get current resolution :
Global Const WM_HORZRES = 8
Global Const WM_VERTRES = 10

Declare Function WM_apiGetDeviceCaps _
Lib "gdi32" Alias "GetDeviceCaps" _
(ByVal hdc As Long, ByVal nIndex As Long) As Long
Declare Function WM_apiGetDesktopWindow _
Lib "user32" Alias "GetDesktopWindow" () As Long
Declare Function WM_apiGetDC _
Lib "user32" Alias "GetDC" _
(ByVal hwnd As Long) As Long
Declare Function WM_apiReleaseDC _
Lib "user32" Alias "ReleaseDC" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function WM_apiGetSystemMetrics _
Lib "user32" Alias "GetSystemMetrics" _
(ByVal nIndex As Long) As Long

Function xg_GetScreenResolution(DisplayHeight As Integer, DisplayWidth As Integer) As String
'return the display height and width
'Dim DisplayHeight As Integer
'Dim DisplayWidth As Integer
Dim hDesktopWnd As Long
Dim hDCcaps As Long
Dim iRtn As Integer

'* make API calls to get desktop settings
hDesktopWnd = WM_apiGetDesktopWindow() 'get handle to desktop
hDCcaps = WM_apiGetDC(hDesktopWnd) 'get display context for desktop
DisplayHeight = WM_apiGetDeviceCaps(hDCcaps, WM_VERTRES)
DisplayWidth = WM_apiGetDeviceCaps(hDCcaps, WM_HORZRES)
iRtn = WM_apiReleaseDC(hDesktopWnd, hDCcaps) 'release display context

'MsgBox "Desktop display width is " & DisplayWidth & " pixels."
'MsgBox "Desktop display height is " & DisplayHeight & " pixels."

xg_GetScreenResolution = DisplayWidth & "x" & DisplayHeight

End Function
2. Get old resolution and if old <>
   current, resize form:
Private Sub Convert(x As Integer, xOld As Integer, _
                    y As Integer, yOld As Integer)
   Dim fForm As Form, iControl As Control
   Dim DB As Database
   Dim i As Integer
   Dim xMax As Integer, yMax As Integer
   
   Set DB = CurrentDb()
            DoCmd.OpenForm "MyForm", acDesign, , , acFormPropertySettings, acHidden
     Set fForm = [Forms]![MyForm]
     xMax = 0
     yMax = 0
     For Each iControl In fForm.Controls
          With iControl
             .Height = .Height * y / yOld
             .Width = .Width * x / xOld
             .Left = .Left * x / xOld
             .Top = .Top * y / yOld
             On Error Resume Next
             .FontSize = .FontSize * y / yOld
             If .FontSize < 8 Then .FontSize = 8
             If .ControlType = acLabel Then
                .SizeToFit 'first buttons!
             End If
             xMax = IIf(.Left + .Width > xMax, .Left + .Width, xMax)
             yMax = IIf(.Top + .Height > yMax, .Top + .Height, yMax)
          End With
       'End If
     Next iControl
     fForm.Width = xMax + 10
     fForm.Detail.Height = yMax + 10
     
     DoCmd.Close acForm, "MyForm", acSaveYes
End Sub

Happy New Year. Alex
lcleary:  Welcome to EE.

FMS, as Tom mentioned, makes two resizing products - Form Resizer, which is part of their Access Components package and Sizer, which is a VB 5/6 ActiveX control.  No one to my knowledge has really tried Sizer with Access but with some playing with it might work.

The Forms Resizer will allow a user to increase the size of a form to fill a window with higher resolution.  If there are several subforms within the form, they will resize also.

We have used the product but remed it out while we were developing the product as the ActiveX caused all kinds of additional problems in the development cycle.  We shipped the first release with 800 X 600 resolution and so far, no one has complained about it.

Jim
Icleary, what do you think about all
prepositions?
ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial