Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub Form_Resize()
If frmMain.WindowState <> vbMinimized Then
With Form1
RTB.Move .ScaleLeft, .ScaleTop, .ScaleWidth, .ScaleHeight
End With
End If
End Sub
form1.BorderStyle = 1
Option Explicit
Dim intDefaultHeight As Long
Dim intDefaultWidth As Long
Dim arrControls()
Dim i As Integer
Dim ctl As Control
Private Sub Form_Load()
Dim intControls As Integer
' Store original height and width of the form
intDefaultHeight = Me.Height
intDefaultWidth = Me.Width
' Find how many controls there are
For Each ctl In Me.Controls
intControls = intControls + 1
Next
' set an array which is sized to the number of controls and with 3 elements (for height, width, top and left)
ReDim arrControls(intControls, 3)
' loop through each control and add the value to each element
i = 0
For Each ctl In Me.Controls
arrControls(i, 0) = ctl.Height
arrControls(i, 1) = ctl.Width
arrControls(i, 2) = ctl.Top
arrControls(i, 3) = ctl.Left
i = i + 1
Next
End Sub
Private Sub Form_Resize()
Dim intHeight As Long
Dim intWidth As Long
' get the new height and width of the form
intHeight = Me.Height
intWidth = Me.Width
' loop through each control and assign a new value based on the % change that the user ahs applied
i = 0
For Each ctl In Me.Controls
ctl.Height = arrControls(i, 0) * (intHeight / intDefaultHeight)
ctl.Width = arrControls(i, 1) * (intWidth / intDefaultWidth)
ctl.Top = arrControls(i, 2) * (intHeight / intDefaultHeight)
ctl.Left = arrControls(i, 3) * (intWidth / intDefaultWidth)
i = i + 1
Next
End Sub
'!! PLACE THE FOLLOWING CODE IN A FRM
Option Explicit
'!! THE CLASS IS USED IN THE FOLLOWING WAY
'!! Add the following CMDs to the FRM: cmdMatchWidth, cmdMatchHeight, cmdStayBottomRight
Private mclsFRMResizer As cFRMResizer
'
Private Sub Form_Load()
'===============================================================================
'!! THE FOLLOW LINES ARE FOR THIS EXAMPLE
'-- Setup FRM
With Me
.BorderStyle = 2: .Width = 4755: .Height = 3600
End With
'-- Setup CMDs
With Me.cmdMatchWidth
.Left = 60: .Top = 60: .Width = 4515: .Height = 495
End With
With Me.cmdMatchHeight
.Left = 60: .Top = 600: .Width = 1455: .Height = 2535
End With
With Me.cmdStayBottomRight
.Left = 3120: .Top = 2640: .Width = 1455: .Height = 495
End With
'-- Initialize and setup 'CFRMResizer'
Set mclsFRMResizer = New cFRMResizer
Call mclsFRMResizer.Setup(Me)
With mclsFRMResizer
' ex.: .AddCTL [enuFRMResizeType_X], [enuFRMResizeType_Y}
.AddCTL Me.cmdMatchWidth, ertGrow
.AddCTL Me.cmdMatchHeight, , ertGrow
.AddCTL Me.cmdStayBottomRight, ertMove, ertMove
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
'===============================================================================
Set mclsFRMResizer = Nothing
End Sub
'!! PLACE THE FOLLOWING IN A MODULE
Option Explicit
'-- The following is used in 'CFRMResizer'
Public Enum enuFRMResizeTypes
ertGrow = 1 '-- CTL's height/width should increase
ertMove '-- CTL's top/left should increase
End Enum
'!! PLACE THE FOLLOWING IN A CLASS MODULE WITH THE NAME 'cFRMResizer'
Option Explicit
Private Type typResizeCTL
ctl As Control
'-- Defines the X and Y behavior at resize time
' (height/top or width/left increased)
enuFRMResizeType_X As enuFRMResizeTypes
enuFRMResizeType_Y As enuFRMResizeTypes
'-- Used internally for determining new height/top or width/left
lngOrigCTL_X As Long
lngOrigCTL_Y As Long
End Type
Private matypResizeCTLs() As typResizeCTL
Private mintUBound As Integer
Private mlngOrigFRMHeight As Long
Private mlngOrigFRMWidth As Long
Private WithEvents mfrm As Form
'
Private Sub Class_Initialize()
'===============================================================================
ReDim matypResizeCTLs(0)
End Sub
Private Sub Class_Terminate()
'===============================================================================
Erase matypResizeCTLs()
Set mfrm = Nothing
End Sub
Public Sub Setup(frm As Form)
'===============================================================================
Set mfrm = frm
'-- Store original FRM height and width
With mfrm
mlngOrigFRMHeight = .Height
mlngOrigFRMWidth = .Width
End With
End Sub
Public Sub AddCTL(ctl As Control, Optional enuFRMResizeType_X As enuFRMResizeTypes _
, Optional enuFRMResizeType_Y As enuFRMResizeTypes)
'===============================================================================
'-- If there aren't any elements
If Not (mintUBound = 0 And matypResizeCTLs(0).ctl Is Nothing) Then
'-- Increase array
mintUBound = mintUBound + 1
ReDim Preserve matypResizeCTLs(mintUBound)
End If
With matypResizeCTLs(mintUBound)
Set .ctl = ctl
'-- Store "X" resize type and determine which "X" value to store in lngOrigCTL_X
.enuFRMResizeType_X = enuFRMResizeType_X
Select Case enuFRMResizeType_X
Case ertGrow: .lngOrigCTL_X = ctl.Width
Case ertMove: .lngOrigCTL_X = ctl.Left
End Select
'-- Store "Y" resize type and determine which "Y" value to store in lngOrigCTL_Y
.enuFRMResizeType_Y = enuFRMResizeType_Y
Select Case enuFRMResizeType_Y
Case ertGrow: .lngOrigCTL_Y = ctl.Height
Case ertMove: .lngOrigCTL_Y = ctl.Top
End Select
End With
End Sub
Private Sub mfrm_Resize()
'===============================================================================
Dim lngCounter As Long
Dim lngFRMHeight As Long
Dim lngFRMWidth As Long
Dim lngNewValue As Long
'-- Make sure height and width are not less than the original
With mfrm
If .Height < mlngOrigFRMHeight Then .Height = mlngOrigFRMHeight
If .Width < mlngOrigFRMWidth Then .Width = mlngOrigFRMWidth
lngFRMHeight = .Height
lngFRMWidth = .Width
End With
For lngCounter = 0 To mintUBound
With matypResizeCTLs(lngCounter)
'-- If a resize type was saved for this CTL's "X"
If .enuFRMResizeType_X > 0 Then
'-- Get new value from mlngOrigFRMWidth and CTL's lngOrigCTL_X
lngNewValue = lngFRMWidth - (mlngOrigFRMWidth - .lngOrigCTL_X)
Select Case .enuFRMResizeType_X
Case ertGrow: .ctl.Width = lngNewValue
Case ertMove: .ctl.Left = lngNewValue
End Select
End If
'-- If a resize type was saved for this CTL's "Y"
If .enuFRMResizeType_Y > 0 Then
'-- Get new value from mlngOrigFRMHeight and CTL's .lngOrigCTL_Y
lngNewValue = lngFRMHeight - (mlngOrigFRMHeight - .lngOrigCTL_Y)
Select Case .enuFRMResizeType_Y
Case ertGrow: .ctl.Height = lngNewValue
Case ertMove: .ctl.Top = lngNewValue
End Select
End If
End With
Next lngCounter
End Sub