0% found this document useful (0 votes)
48 views2 pages

Centering and Resizing Forms in Code

This document provides code to center a form in the middle of the screen and resize forms with a stretch effect. The centering code uses the screen height and width to calculate the form's top and left positions. The resizing code stores original control properties, resizes controls proportionally based on the new form size within minimum and maximum bounds, and adjusts font sizes between 8-12 points.

Uploaded by

isacon 2021
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views2 pages

Centering and Resizing Forms in Code

This document provides code to center a form in the middle of the screen and resize forms with a stretch effect. The centering code uses the screen height and width to calculate the form's top and left positions. The resizing code stores original control properties, resizes controls proportionally based on the new form size within minimum and maximum bounds, and adjusts font sizes between 8-12 points.

Uploaded by

isacon 2021
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Center A Form

Here's how to center a form so it will appear in the middle of the screen, put this
in a button:

[Link] = ([Link] - [Link]) / 2


[Link] = ([Link] - [Link]) / 2

Resizing a Form (an easy way)


This code lets you resize your forms with a neat stretch effect. Copy and paste the
code as directed by the comments:

'-----------------------------------------------------
' Put this code in the public area of your form (ie, the top most part)
'-----------------------------------------------------

Private Type ScaleStruct


Top As Integer
Left As Integer
Width As Integer
Height As Integer
ParentHeight As Integer
ParentWidth As Integer
FontSize As Integer
End Type

Dim Ctrl() As ScaleStruct


Dim minWidth As Integer
Dim minHeight As Integer
Dim maxWidth As Integer
Dim maxHeight As Integer

'-----------------------------------------------------
' Put this code in the Form_Load event
'-----------------------------------------------------

On Error Resume Next

Dim i As Integer
ReDim Ctrl(0 To [Link] - 1)

[Link] = 3

For i = 0 To [Link] - 1
Ctrl(i).Top = [Link](i).Top
Ctrl(i).Left = [Link](i).Left
Ctrl(i).Width = [Link](i).Width
Ctrl(i).Height = [Link](i).Height
Ctrl(i).ParentHeight = [Link](i).[Link]
Ctrl(i).ParentWidth = [Link](i).[Link]
Ctrl(i).FontSize = [Link](i).FontSize
Next

' THESE VALUES ARE ARBITRARY


' Change them to best suit your program
' One tip would be to have a min size, but not a real
' max size (ie, make the maxes larger than what the
' screen size will ever be
minWidth = 400
minHeight = 400
maxWidth = 800
maxHeight = 800

'-----------------------------------------------------
' Put this code in the Form_Resize event
'-----------------------------------------------------

On Error Resume Next

Dim i As Integer
Dim ParentSH As Integer, ParentSW As Integer

ParentSH = [Link](i).[Link]
ParentSW = [Link](i).[Link]

For i = 0 To [Link] - 1
If [Link] >= minHeight And [Link] <= maxHeight Then
[Link](i).Top = Ctrl(i).Top * (ParentSH / Ctrl(i).ParentHeight)
[Link](i).Height = Ctrl(i).Height * (ParentSH / Ctrl(i).ParentHeight)
[Link](i).FontSize = Ctrl(i).FontSize * (ParentSH /
Ctrl(i).ParentHeight)
If [Link](i).FontSize < 8 Then [Link](i).FontSize = 8
If [Link](i).FontSize > 12 Then [Link](i).FontSize = 12
End If

If [Link] >= minWidth And [Link] <= maxWidth Then


[Link](i).Left = Ctrl(i).Left * (ParentSW / Ctrl(i).ParentWidth)
[Link](i).Width = Ctrl(i).Width * (ParentSW / Ctrl(i).ParentWidth)
End If
Next

You might also like