473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any good Form Resizing code?

I have some old code that I use from the Access 95 Developers handbook. The
code works very well, with the exception that it doesn't seem to recognize
wide screens, and sizes tab controls so that they are too big and wind up
covering up some of the fields on the main form.

Is there any good code out there that works in a similar fashion that will
also either a) stretch the form width wise on widescreens or b), rely on
height rather than width to resize the form. My VB skill isn't that great,
so I'm not able to modify this code to do what I want. (I've pasted the
code I'm using below).

Any ideas?

Thanks!


Option Compare Database 'Use database order for string comparisons
Option Explicit

' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.

' Store rectangle coordinates.
Type glrTypeRect
X1 As Long
Y1 As Long
X2 As Long
Y2 As Long
End Type

Declare Function glr_apiIsIconic Lib "user32" _
Alias "IsIconic" (ByVal hwnd As Long) As Long

Declare Function glr_apiGetDevic eCaps Lib "gdi32" _
Alias "GetDeviceC aps" (ByVal hdc As Long, _
ByVal nIndex As Long) As Long

Declare Function glr_apiGetWindo wRect Lib "user32" _
Alias "GetWindowR ect" (ByVal hwnd As Long, _
lpRect As glrTypeRect) As Long

Declare Function glr_apiGetParen t Lib "user32" _
Alias "GetParent" (ByVal hwnd As Long) As Long

Declare Function glr_apiGetClien tRect Lib "user32" _
Alias "GetClientR ect" (ByVal hwnd As Long, _
lpRect As glrTypeRect) As Long

Declare Function glr_apiGetWindo wLong Lib "user32" _
Alias "GetWindowLongA " (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long

Declare Function glr_apiGetSyste mMetrics Lib "user32" _
Alias "GetSystemMetri cs" (ByVal nIndex As Long) As Long

Declare Function glr_apiGetSyste mMenu Lib "user32" _
Alias "GetSystemM enu" (ByVal hwnd As Long, _
ByVal bRevert As Long) As Long

Declare Function glr_apiGetActiv eWindow Lib "user32" _
Alias "GetActiveWindo w" () As Long

'============== =============== =============== =============== ============

' Store group/subform dimensions.
Type glrTypeDimensio ns
sglLeft As Single
sglTop As Single
sglWidth As Single
sglHeight As Single
strCtlName As String
End Type

' These are the class names used in Access.
Public Const glrcAccessClass = "OMain"
Public Const glrcMDIClientCl ass = "MDICLIENT"
Public Const glrcAccessDBCCl ass = "ODb"
Public Const glrcAccessFormC lass = "OForm"

' Windows API declarations.
Declare Function glr_apiCreateIC Lib "gdi32" _
Alias "CreateICA" (ByVal lpDriverName As String, _
ByVal lpDeviceName As String, ByVal lpOutput As String, _
lpInitData As Any) As Long

Declare Function glr_apiDeleteDC Lib "gdi32" _
Alias "DeleteDC" (ByVal hdc As Long) As Long

Declare Function glr_apiMoveWind ow Lib "user32" _
Alias "MoveWindow " (ByVal hwnd As Long, _
ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Declare Function glr_apiSetWindo wLong Lib "user32" _
Alias "SetWindowLongA " (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Declare Function glr_apiEnableMe nuItem Lib "user32" _
Alias "EnableMenuItem " (ByVal hMenu As Long, _
ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long

Declare Function glr_apiGetWindo w Lib "user32" _
Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Declare Function glr_apiGetClass Name Lib "user32" _
Alias "GetClassNa meA" (ByVal hwnd As Long, _
ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Declare Function glr_apiFindWind ow Lib "user32" _
Alias "FindWindow A" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Declare Function glr_apiGetNextW indow Lib "user32" _
Alias "GetNextWin dow" (ByVal hwnd As Long, _
ByVal wFlag As Long) As Long

Declare Function glr_apiSetFocus Lib "user32" _
Alias "SetFocus" (ByVal hwnd As Long) As Long

' Get a string from a private INI file. Returns the number of bytes
' copied into strReturned, not including the trailing null.
Declare Function glr_apiGetPriva teProfileString Lib "kernel32" _
Alias "GetPrivateProf ileStringA" (ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedStrin g As String, ByVal nSize As Long, _
ByVal lpFileName As String) As Long

' Write a string to a private INI file. Returns a non-zero value if
successful,
' otherwise it returns a 0.

Declare Function glr_apiWritePri vateProfileStri ng Lib "kernel32" _
Alias "WritePrivatePr ofileStringA" (ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As
String) As Long

' These functions aren't actually used
' but are provided here for reference only.

' Get a string from WIN.INI. Returns the number of bytes copied into
strReturned,
' not including the trailing null.
Declare Function glr_apiGetProfi leString Lib "kernel32" _
Alias "GetProfileStri ngA" (ByVal lpglrcAppName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedStrin g As String, ByVal nSize As Long) As Long

' Get an integer from WIN.INI. Returns either the integer it found,
' or the value sent in intDefault.
Declare Function glr_apiGetProfi leInt Lib "kernel32" _
Alias "GetProfileIntA " (ByVal lpglrcAppName As String, _
ByVal lpKeyName As String, ByVal nDefault As Long) As Long

' Write a string to WIN.INI. Returns a non-zero value if successful,
' otherwise it returns a 0.
Declare Function WriteProfileStr ing Lib "kernel32" _
Alias "WriteProfileSt ringA" (ByVal lpszSection As String, _
ByVal lpszKeyName As String, ByVal lpszString As String) As Long

' Get an integer from a private INI file. Returns either the integer it
found,
' or the value sent in intDefault.
Declare Function GetPrivateProfi leInt Lib "kernel32" _
Alias "GetPrivateProf ileIntA" (ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, ByVal nDefault As Long, _
ByVal lpFileName As String) As Long

' GetNextWindow() constants
Public Const glrcGW_CHILD = 5
Public Const glrcGW_HWNDNEXT = 2

' Action constants
Public Const glrcMF_BYCOMMAN D = &H0
Public Const glrcMF_DISABLED = &H2
Public Const glrcMF_ENABLED = &H0
Public Const glrcMF_GRAYED = &H1

' Menu item name constants
Public Const glrcSC_SIZE = &HF000
Public Const glrcSC_MOVE = &HF010
Public Const glrcSC_MINIMIZE = &HF020
Public Const glrcSC_MAXIMIZE = &HF030
Public Const glrcSC_NEXTWIND OW = &HF040
Public Const glrcSC_CLOSE = &HF060
Public Const glrcSC_RESTORE = &HF120

' Windows API Constants
Public Const glrcVERTRES = 10
Public Const glrcHORZRES = 8
Public Const glrcLOGPIXELSX = 88
Public Const glrcLOGPIXELSY = 90

' General Constants
Public Const glrcTwipsPerInc h = 1440

' GetWindowLong Constant
Public Const glrcGWL_STYLE = -16

' Windows Style constant
Public Const glrcWS_CAPTION = &HC00000

' System Metrics Constant
Public Const glrcSM_CYCAPTIO N = 4
Public Const glrcSM_CXFULLSC REEN = 16
Public Const glrcSM_CYFULLSC REEN = 17

Function IsSubForm(frm As Form) As Boolean
' Is the form referenced in the
' parameter currently loaded as a subform?
' Check its Parent property to find out.

' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.

' In:
' frm: a reference to the form in question
' Out:
' Return value: True if the form is a subform
' False if it's a standalone form
Dim strName As String
On Error Resume Next
strName = frm.Parent.name
IsSubForm = (Err = 0)
On Error GoTo 0
End Function

Option Compare Database 'Use database order for string comparisons
Option Explicit

' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.

' Constants that aren't there, that probably should be.
Const acWindow = 7
Const acSizeToFit = 6
Const acDatasheetView = 2

' Enumerated constants for GetTwips()
Const glrcXAxis = 0
Const glrcYAxis = 1

' The maximum size for a form is 22 inches.
Const glrcMaxTwips = 22 * glrcTwipsPerInc h

' These constants should not require changing.
' 1280x1024, 1024x768 use 12 and 12.
' 640x480 and 800x600 use 15 and 15.
'
Const glrcDesignXTwip sLoRes = 15
Const glrcDesignYTwip sLoRes = 15
Const glrcDesignXTwip sHiRes = 12
Const glrcDesignYTwip sHiRes = 12

' Keep track of the previous/original size for the form.
' Dim rctOriginal As glrTypeRect

' Error constants
Const glrcErrDivision ByZero = 11
Const glrcErrInvalidP roperty = 2455

Private Function ChangeFont(Ctl As Control) As Boolean

' Decide whether or not to change the font,
' based on the control type.

Dim fDoit As Integer
fDoit = False
Select Case Ctl.ControlType
Case acTextBox, acComboBox, acListBox, acLabel, _
acCommandButton , acToggleButton
fDoit = True
Case Else
fDoit = False
End Select
ChangeFont = fDoit
End Function

Private Function ChangeHeight(Ct l As Control) As Boolean

' Decide whether or not to change the height,
' based on the control type.

Dim fDoit As Integer
fDoit = True
Select Case Ctl.ControlType
Case acCheckBox, acOptionButton, acPageBreak, acPage
fDoit = False
Case Else
fDoit = True
End Select
ChangeHeight = fDoit
End Function

Private Function FixGroups(frm As Form, aGroups() As glrTypeDimensio ns,
sglFactorX As Single, sglFactorY As Single)

' Store away information about controls that
' contain other controls (subforms/subgroups).
' Return the number of these controls that
' were found.

Dim intI As Integer
Dim fDoit As Boolean
Dim intGroups As Integer

intGroups = 0
For intI = 0 To frm.Count - 1
With frm(intI)
Select Case .ControlType
Case acOptionGroup, acSubform
fDoit = True
Case Else
fDoit = False
End Select
If fDoit Then
intGroups = intGroups + 1
ReDim Preserve aGroups(intGrou ps)

aGroups(intGrou ps).strCtlName = .name
aGroups(intGrou ps).sglLeft = .Left * sglFactorX
aGroups(intGrou ps).sglTop = .Top * sglFactorY
aGroups(intGrou ps).sglWidth = .Width * sglFactorX
aGroups(intGrou ps).sglHeight = .Height * sglFactorY
End If
End With
Next intI
FixGroups = intGroups
End Function

Private Sub FixSections(frm As Form, sglFactorY As Single)

' Loop through all the sections of the form,
' up to 5 sections, setting the height of
' each. If a section isn't there, just keep
' on going.

Dim intI As Integer
Dim varTemp As Variant

' There are 5 possible sections in a form,
' but they might not all be there.
On Error Resume Next
With frm
For intI = 0 To 4
varTemp = .Section(intI). Height * sglFactorY
.Section(intI). Height = IIf(varTemp > glrcMaxTwips,
glrcMaxTwips, varTemp)
Next intI
End With
End Sub

Private Sub GetFormSize(frm As Form, rct As glrTypeRect)

' Fill in rct with the coordinates of the window.

Dim hWndParent As Long
Dim rctParent As glrTypeRect

' Find the position of the window in question, in
' relation to its parent window (the Access desktop,
' the MDIClient window).
hWndParent = glr_apiGetParen t(frm.hwnd)

' Get the coordinates of the current window and its parent.
glr_apiGetWindo wRect frm.hwnd, rct

' Catch the case where the form is Popup (that is,
' its parent is NOT the Access main window.) In that
' case, don't subtract off the coordinates of the
' Access MDIClient window.
If hWndParent <> Application.hWn dAccessApp Then
glr_apiGetWindo wRect hWndParent, rctParent

' Subtract off the left and top parent coordinates, since you
' need coordinates relative to the parent for the
glr_apiMoveWind ow()
' function call.
With rct
.X1 = .X1 - rctParent.X1
.Y1 = .Y1 - rctParent.Y1
.X2 = .X2 - rctParent.X1
.Y2 = .Y2 - rctParent.Y1
End With
End If
End Sub

Private Sub GetScreenScale( intX As Integer, intY As Integer, sglFactorX As
Single, sglFactorY As Single)
' In: intX, intY: x and y screen resolutions
' when the form was created.
' Out: sglFactorX, sglFactorY: scaling factors for
' the x and y directions.

Dim intScreenX As Integer
Dim intScreenY As Integer

Dim intTwipsPerPixe lX As Integer
Dim intTwipsPerPixe lY As Integer

Dim lngIC As Long

On Error GoTo GetScreenScaleE rror

' Get the information context you need to find the screen info.
lngIC = glr_apiCreateIC ("DISPLAY", vbNullString, _
vbNullString, vbNullString)

' If the call to CreateIC didn't fail, then get the info.
If lngIC <> 0 Then
' Find the number of pixels in both directions on the
' screen, (640x480, 800x600, 1024x768, 1280x1024?). This
' also takes into account the size of the task bar, whereever
' it is.
intScreenX = glr_apiGetSyste mMetrics(glrcSM _CXFULLSCREEN)
intScreenY = glr_apiGetSyste mMetrics(glrcSM _CYFULLSCREEN)

' Find the number of twips per pixel in both directions.
intTwipsPerPixe lX = glrcTwipsPerInc h / glr_apiGetDevic eCaps(lngIC,
glrcLOGPIXELSX)
intTwipsPerPixe lY = glrcTwipsPerInc h / glr_apiGetDevic eCaps(lngIC,
glrcLOGPIXELSY)

' Release the information context.
glr_apiDeleteDC lngIC

' Get the ratio of the current screen size to the design-time
' screen size.

sglFactorX = intScreenX / intX
sglFactorY = intScreenY / intY

' Finally, take into account the differences in the display
' resolutions. At 640x480, you get more twips per pixel (15)
' as opposed to 12 at higher resolutions.
' Note: GetTwips always takes the X RESOLUTION as its first
parameter.
sglFactorX = sglFactorX * (intTwipsPerPix elX / GetTwips(intX,
glrcXAxis))
sglFactorY = sglFactorY * (intTwipsPerPix elY / GetTwips(intX,
glrcYAxis))
End If

GetScreenScaleE xit:
Exit Sub

GetScreenScaleE rror:
Select Case Err.Number
Case glrcErrDivision ByZero
' It seems that the first time you call
' GetDeviceCaps under Win95 after you've done
' a quick change on the resolution, it returns 0
' for the screen size. This will hopefully correct
' that problem.
Resume
Case Else
HandleError "GetScreenScale ", Err.Number, Err.Description
Resume GetScreenScaleE xit
End Select
End Sub

Private Function GetTwips(intXRe solution As Integer, intAxis As Integer)

' Experience has shown that the twips/pixel ratios
' are dependent on the screen resolution. If you find this
' not to be true in your particular case, you'll need to modify
' this routine.

Select Case intXResolution
Case 1024, 1280
GetTwips = IIf(intAxis = glrcXAxis, _
glrcDesignXTwip sHiRes, glrcDesignYTwip sHiRes)
Case 640, 800
GetTwips = IIf(intAxis = glrcXAxis, _
glrcDesignXTwip sLoRes, glrcDesignYTwip sLoRes)
Case Else
' If the value is invalid, just assume the designed used
' a high-res screen. The worst this can do is cause
' an image that's a little small.
GetTwips = IIf(intAxis = glrcXAxis, _
glrcDesignXTwip sHiRes, glrcDesignYTwip sHiRes)
End Select
End Function

Function glrResizeForm(f rm As Form, ByVal fDoResize As Variant, rctOriginal
As glrTypeRect)

' 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 Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. 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 glrTypeRect
Dim rctClient As glrTypeRect
Dim varTemp As Variant
Dim intWidth As Integer
Dim intHeight As Integer
Dim sglFactorX As Single
Dim sglFactorY As Single
On Error GoTo glrResizeWindow Error
' 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.
glr_apiGetClien tRect frm.hwnd, rctNew
intHeight = (rctNew.Y2 - rctNew.Y1)
If intHeight = 0 Or glr_apiIsIconic (frm.hwnd) Then
Exit Function
End If

' Get the current width. Already found the
' current height.
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

glrResizeWindow Exit:
Exit Function

glrResizeWindow Error:
If Err = glrcErrDivision ByZero Then
sglFactorX = 1
sglFactorY = 1
Resume sglFactorOK
Else
HandleError "glrResizeForm" , Err.Number, Err.Description
Resume Next
End If
End Function

Function glrScaleForm(fr m As Form, intX As Integer, intY As Integer,
rctOriginal As glrTypeRect)

' Called from the Open event of forms.
' Attempts to scale the form appropriately
' for the given screen size, as compared
' to the size screen on which it was designed.

' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.
'
' In:
' frm: A reference to the form in question
' intX: the horizontal screen resolution at which the form was
designed.
' intY: the vertical screen resolution at which the form was
designed.
' rctOriginal: original coordinates
'
' Out:
' Nothing
' Comments:
' Use a function call like this:
' intRetval = glrScaleForm(Me , 640, 480, rctOriginal)
' to autoscale a form created at 640x480 resolution.

Dim intTwipsPerPixe lX As Integer
Dim intTwipsPerPixe lY As Integer
Dim intScreenX As Integer
Dim intScreenY As Integer

Dim sglFactorX As Single
Dim sglFactorY As Single

GetScreenScale intX, intY, sglFactorX, sglFactorY

' Whether or not this form gets rescaled,
' you'll need to store away the current size
' for later. The reason you must call GetFormSize
' here, rather than glr_apiGetClien tRect, is that
' you need the screen positioning information
' which you don't get with GetClientRect.
GetFormSize frm, rctOriginal

' If the x and y factors are both 1, there's nothing
' to do, so get out here.
If (sglFactorX = 1) And (sglFactorY = 1) Then Exit Function

' If you don't want forms to expand (they were created on a
' lower-resolution device than the current device), but only
' shrink (they were created on a higher-resolution device
' than the current device), then uncomment the next line.
'If (sglFactorX > 1) And (sglFactorY > 1) Then Exit Sub
DoCmd.RepaintOb ject
SetFormSize frm, sglFactorX, sglFactorY, rctOriginal, True
End Function
Private Sub HandleError(str Function As String, intErr As Integer, strError
As String)
MsgBox "Error: " & strError & " (" & intErr & ")", vbExclamation,
strFunction
End Sub

Private Sub SetFormSize(frm As Form, sglFactorX As Single, sglFactorY As
Single, rct As glrTypeRect, fMove As Integer)

' Actually do the work to resize all the controls
' on the given form, and then resize the form
' itself.

Dim intTemp As Integer
Dim intWidth As Integer
Dim intHeight As Integer
Dim Ctl As Control
Dim sglFontSize As Single
Dim intI As Integer
Dim intGroups As Integer
Dim aGroups() As glrTypeDimensio ns
Dim colGroups As New Collection
Dim varTemp As Variant

On Error GoTo SetFormSizeErro r

DoCmd.Hourglass True
frm.Painting = False

' If the form is growing vertically, then need to
' fix up the section heights now. If it's shrinking,
' fix up the heights AFTER you place the controls.
' The same goes for the form width.
If sglFactorY > 1 Then
' Fix up all the section heights.
FixSections frm, sglFactorY
varTemp = frm.Width * sglFactorX
If varTemp > glrcMaxTwips Then
frm.Width = glrcMaxTwips
Else
frm.Width = varTemp
End If
End If

' Now deal with all the controls
' Go through and deal with all the groups and subforms first.
intGroups = FixGroups(frm, aGroups(), sglFactorX, sglFactorY)

' Now go back and deal with all the rest of the controls.
For Each Ctl In frm.Controls

Select Case Ctl.ControlType
Case acOptionGroup
GoTo NextCtl

Case acSubform
' If you've got a subform, then recurse on down into this
' routine again, dealing with all the controls inside of
' that subform.
SetFormSize Ctl.Form, sglFactorX, sglFactorY, rct, False

GoTo NextCtl
Case acPage
'an acPage, is a 'tab page' on a tab control
'The 'tab page' is automatically resized by the tab control
when the tab control itself is resized
'so.. don't resize the tab page. If the tab page WERE TO BE
resized, the tab control will automatically
'resize itself to match the page size (i.e. tab control
resizes increasing the page size, then page is resized
'increasing the tabcontrol size, then the next page is
resized, which again resizes everything etc, etc etc....
'the tab control would grow X times for each page on it)
GoTo NextCtl
End Select

' So the control isn't a subform and it's not a group.
' Therefore, just scale it to the correct size.

' First, fix up the font, if this control has a font
' that needs to be fixed up.
If ChangeFont(Ctl) Then
sglFontSize = Ctl.FontSize * sglFactorY
Else
sglFontSize = -1
End If

' Set the top, left and width values.

If frm.CurrentView <> acDatasheetView Then
Ctl.Top = Ctl.Top * sglFactorY
Ctl.Left = Ctl.Left * sglFactorX
Ctl.Width = Ctl.Width * sglFactorX
End If

' Change the height, if that's required.
If ChangeHeight(Ct l) Then
Ctl.Height = Ctl.Height * sglFactorY
End If

' Only attempt to change the font size for
' certain types of controls.
If sglFontSize >= 1 And sglFontSize <= 127 Then
Ctl.FontSize = sglFontSize
End If
NextCtl:
Next Ctl

' If the form is shrinking vertically, fix up the
' section heights now that all the controls have been
' placed. The same goes for the form width.
If sglFactorY < 1 Then
' Fix up all the section heights.
FixSections frm, sglFactorY
frm.Width = frm.Width * sglFactorX
End If

' Go through and fix up the option groups/subforms,
' which may have been distorted by changes to
' the internal controls.
For intI = 1 To intGroups
With frm(aGroups(int I).strCtlName)
.Top = aGroups(intI).s glTop
.Left = aGroups(intI).s glLeft
.Width = aGroups(intI).s glWidth
.Height = aGroups(intI).s glHeight
End With
Next intI

If fMove Then
intWidth = Int((rct.X2 - rct.X1) * sglFactorX)
intHeight = Int((rct.Y2 - rct.Y1) * sglFactorY)

rct.X1 = Int(rct.X1 * sglFactorX)
rct.Y1 = Int(rct.Y1 * sglFactorY)
rct.X2 = rct.X1 + intWidth
rct.Y2 = rct.Y1 + intHeight

intTemp = glr_apiMoveWind ow(frm.hwnd, rct.X1, rct.Y1, intWidth,
intHeight, True)

' Use the Window-Size To Fit menu item.
DoCmd.DoMenuIte m acFormBar, acWindow, acSizeToFit, , acMenuVer70

End If

SetFormSizeExit :
frm.Painting = True
DoCmd.Hourglass False
Exit Sub

SetFormSizeErro r:
Select Case Err
Case glrcErrInvalidP roperty
Resume Next
Case Else
'HandleError "SetFormSiz e", Err.Number, Error.Descripti on
Resume Next
End Select
End Sub


Nov 13 '05 #1
11 18813
Jozef wrote:
I have some old code that I use from the Access 95 Developers
handbook. The code works very well, with the exception that it
doesn't seem to recognize wide screens, and sizes tab controls so
that they are too big and wind up covering up some of the fields on
the main form.

Is there any good code out there that works in a similar fashion that
will also either a) stretch the form width wise on widescreens or b),
rely on height rather than width to resize the form. My VB skill
isn't that great, so I'm not able to modify this code to do what I
want. (I've pasted the code I'm using below).

Any ideas?


A question to consider first. Why do you think you need to make your app
larger on higher resolution screens? Do you see any other "normal" apps
that do this?

People run their screens at higher resolutions to see *more* stuff, not
*bigger* stuff.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2
Rick Brandt wrote:
A question to consider first. Why do you think you need to make your app
larger on higher resolution screens? Do you see any other "normal" apps
that do this?

People run their screens at higher resolutions to see *more* stuff, not
*bigger* stuff.


Not always, some people have bad eyesight and despite this run at a high
resolution either from their own stupidity or something imposed on them
by their self esteemed IT departments.

I generally design a form so it looks neat, not with half the form's
controls out of the visible viewing area. Whether they run at 640x480 or
1600x1200 the application will look like the screen shot in the manual
and help file.

Where more controls are needed than fit in the window I design at, I
used to use page breaks on the form, nowdays I use a tab control.

I use the resizing code from the Access Developer's Handbook (Jozef take
note). It works well most of the time although I do generally modify
that code to take note of subforms that I don't want resized, those with
a gazillion columns across it so that when resized, they see more of the
subform and not a bigger view of it.

I do still get complaints about that, the users want the subform's
controls to get as big as the main form's ones as they say it's too
small, again despite me telling them that if the standard size font is
too small then they are running too high a resolution.

Nov 13 '05 #3
Trevor Best wrote:
Rick Brandt wrote:
A question to consider first. Why do you think you need to make
your app larger on higher resolution screens? Do you see any other
"normal" apps that do this?

People run their screens at higher resolutions to see *more* stuff,
not *bigger* stuff.


Not always, some people have bad eyesight and despite this run at a
high resolution either from their own stupidity or something imposed
on them by their self esteemed IT departments.


If someone buys a larger screen because of a sight impairment and then runs it
at a higher resolution than the smaller display that was replaced then that
suggests that their "impairment " extends beyond their eyesight.

My point stands. If a developer feels that his app is usable at 800 by 600 on a
15 inch monitor then he has no reason to make any of the forms larger when run
at a higher resolution. That setting was chosen by the user with certain
expectations. If they have trouble seeing any of their apps then they should
change the settings accordingly.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #4
Didn't mean to spark a debate, was just looking for an answer to my
question, or at least within the scope of the question . Even if there are
modifications that need to be made to the existing Developers Handbook code,
if you could give me an idea of what I need to do, or what part of the code
I need to look at / change that would be great.

Thanks!

"Rick Brandt" <ri*********@ho tmail.com> wrote in message
news:sW******** *******@newssvr 11.news.prodigy .com..
Trevor Best wrote:
Rick Brandt wrote:
> A question to consider first. Why do you think you need to make
> your app larger on higher resolution screens? Do you see any other
> "normal" apps that do this?
>
> People run their screens at higher resolutions to see *more* stuff,
> not *bigger* stuff.
>


Not always, some people have bad eyesight and despite this run at a
high resolution either from their own stupidity or something imposed
on them by their self esteemed IT departments.


If someone buys a larger screen because of a sight impairment and then
runs it at a higher resolution than the smaller display that was replaced
then that suggests that their "impairment " extends beyond their eyesight.

My point stands. If a developer feels that his app is usable at 800 by
600 on a 15 inch monitor then he has no reason to make any of the forms
larger when run at a higher resolution. That setting was chosen by the
user with certain expectations. If they have trouble seeing any of their
apps then they should change the settings accordingly.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #5
Jozef wrote:
Didn't mean to spark a debate, was just looking for an answer to my
question, or at least within the scope of the question . Even if
there are modifications that need to be made to the existing
Developers Handbook code, if you could give me an idea of what I need
to do, or what part of the code I need to look at / change that would
be great.


As far as I know all of the limitations that were present in resizing code
gimmicks in the past are still there. They have problems with certain
controls (tabs, subforms), and they are a lot better at making forms bigger
than they are at making them smaller (which in my opinion is their only
legitimate purpose).

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #6
Look at "Peter's Software" resizing utility.
http://www.peterssoftware.com/ss.htm

I've used it for customers who insist on running their monitors at 640x400,
but in the long run, it's easier to dump these quirky clients, then waste
resources supporting a very small minority.
-Ed
"Jozef" <me@you.com> wrote in message news:AJR2f.2200 2$ir4.8054@edtn ps90...
Didn't mean to spark a debate, was just looking for an answer to my
question, or at least within the scope of the question . Even if there
are modifications that need to be made to the existing Developers Handbook
code, if you could give me an idea of what I need to do, or what part of
the code I need to look at / change that would be great.

Thanks!

"Rick Brandt" <ri*********@ho tmail.com> wrote in message
news:sW******** *******@newssvr 11.news.prodigy .com..
Trevor Best wrote:
Rick Brandt wrote:
> A question to consider first. Why do you think you need to make
> your app larger on higher resolution screens? Do you see any other
> "normal" apps that do this?
>
> People run their screens at higher resolutions to see *more* stuff,
> not *bigger* stuff.
>

Not always, some people have bad eyesight and despite this run at a
high resolution either from their own stupidity or something imposed
on them by their self esteemed IT departments.


If someone buys a larger screen because of a sight impairment and then
runs it at a higher resolution than the smaller display that was replaced
then that suggests that their "impairment " extends beyond their eyesight.

My point stands. If a developer feels that his app is usable at 800 by
600 on a 15 inch monitor then he has no reason to make any of the forms
larger when run at a higher resolution. That setting was chosen by the
user with certain expectations. If they have trouble seeing any of their
apps then they should change the settings accordingly.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


Nov 13 '05 #7
Ed Robichaud wrote:
Look at "Peter's Software" resizing utility.
http://www.peterssoftware.com/ss.htm

I've used it for customers who insist on running their monitors at 640x400,
but in the long run, it's easier to dump these quirky clients, then waste
resources supporting a very small minority.
-Ed


I wish I could drop clients who make life difficult with their quirks,
if I had a lot of little clients I could but I have a few big ones and
dropping one would be a big financial mistake.
Nov 13 '05 #8
Jozef wrote:
Didn't mean to spark a debate, was just looking for an answer to my
question, or at least within the scope of the question . Even if there are
modifications that need to be made to the existing Developers Handbook code,
if you could give me an idea of what I need to do, or what part of the code
I need to look at / change that would be great.


In the class module, FormResize, look for the comment that begins with
"' Luckily"
' If you've got a subform control,
' call the whole thing recursively.
' Luckily, this can't go more than 2 levels deep.
If ctl.ControlType = acSubform Then
If ScaleThisForm And Len(ctl.SourceO bject) > 0 Then
If InStr(1, ctl.Form.Tag, ":skipresiz e:") = 0 Then
Call ctlr.frm.ScaleF ormContents(dec FactorX, decFactorY)
End If
End If
End If
Next ctlr

This skips the subform if the tag is set, and also subforms that don't
yet have a sourceobject set as this used to error a lot.
Nov 13 '05 #9
"Trevor Best" wrote
' If you've got a subform control,
' call the whole thing recursively.
' Luckily, this can't go more than 2 levels deep.


Unluckily, perhaps, the nesting level has been increased from 3 to 10,
though, IMNSHO, a 10-level nesting of subforms would be unworkable.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1734
by: Perry Zamek | last post by:
I am using the Getz et al approach to form resizing, and have encountered a problem, which doesn't seem to have been mentioned here: If I "squeeze" the form that I want to resize, so that the edge of the form covers some of the objects in the form, the code seems to enter some sort of infinite loop (perhaps - I haven't waited long enough ;-),...
1
5202
by: Terry | last post by:
I've seen several posts from people who have seen this flashing in TreeView's when resizing a form. I've noticed it in my app, but only in the child windows. For example, my main form has a splitter with a TreeView and I do not get the flickering with it. I created a new Form based Windows app. Added a TreeView (dock left), then a...
2
8295
by: Jaikumar | last post by:
Hi, 1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image. 2) In the UserControl1 i am showing one transparent form (form3) when ever user preseed left mouse button. 3) The form3 has one transparent user control (usercontrol2) that paints...
12
6705
by: Søren Reinke | last post by:
Hi there I have a little problem. How do i make sure that a graph is not redrawn while the form with the graph is being resized ? I have tried to add a mouse up/down event handler on the form1, but it dosn't get called when resizing :( I would like to be able to resize my form, but also make sure the graph is
6
51903
by: John Bowman | last post by:
Hi All, I must be missing something really obvious, so I'd appreciate someone helping me out. I have a simple Windows form that currently only has a title bar (aka the Text Property is set) and the MinmizeBox, ControlBox and MaximizeBox(es) are all set to false. It's FormBorderStyle is set to "Fixed Single". Eventually this form will have a...
2
1313
by: Aussie Rules | last post by:
Hi, I have an application that allows a user to select a jpg/gif file and display them in a picture box. The issue is that the pictures are of course different sizes, and therefore they need to be resized some how to fit the space the picturebox uses on the form. Setting the picture boxs size mode to stretch just makes the picture look
6
4530
by: JDeats | last post by:
I have a WinForms based application written for the .NET Framework 2.0 and in this application I need to be able to be able to take some action in code when the user finishes resizing the form. I can easily create an event handler for the SizeChanged form level event, the problem is if the user is using a mouse drag to resize the form this...
9
5279
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from http://blogs.crankygoblin.com/blogs/geoff.appleby/pages/50712.aspx. I've also read the post on this topic by bggraphics, but he doesn't arrive at a final result. The main problem I...
0
1584
by: Peter Anthony | last post by:
It seems kind of strange that if a Form is just moved that Resize events fire. This makes it hard to tell the difference betweeen resizing and moving a Form. I can understand why resizing might also be considered a move (since the Form's location can be thought to be based on one from Top/Bottom and one from Left/Right, and some of these...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.