Professional Documents
Culture Documents
Vip Code
Vip Code
Here's how to center a form so it will appear in the middle of the screen, put this
in a button:
'-----------------------------------------------------
' Put this code in the public area of your form (ie, the top most part)
'-----------------------------------------------------
'-----------------------------------------------------
' Put this code in the Form_Load event
'-----------------------------------------------------
Dim i As Integer
ReDim Ctrl(0 To Me.Controls.Count - 1)
Me.ScaleMode = 3
For i = 0 To Me.Controls.Count - 1
Ctrl(i).Top = Me.Controls(i).Top
Ctrl(i).Left = Me.Controls(i).Left
Ctrl(i).Width = Me.Controls(i).Width
Ctrl(i).Height = Me.Controls(i).Height
Ctrl(i).ParentHeight = Me.Controls(i).Parent.ScaleHeight
Ctrl(i).ParentWidth = Me.Controls(i).Parent.ScaleWidth
Ctrl(i).FontSize = Me.Controls(i).FontSize
Next
'-----------------------------------------------------
' Put this code in the Form_Resize event
'-----------------------------------------------------
Dim i As Integer
Dim ParentSH As Integer, ParentSW As Integer
ParentSH = Me.Controls(i).Parent.ScaleHeight
ParentSW = Me.Controls(i).Parent.ScaleWidth
For i = 0 To Me.Controls.Count - 1
If Me.ScaleHeight >= minHeight And Me.ScaleHeight <= maxHeight Then
Me.Controls(i).Top = Ctrl(i).Top * (ParentSH / Ctrl(i).ParentHeight)
Me.Controls(i).Height = Ctrl(i).Height * (ParentSH / Ctrl(i).ParentHeight)
Me.Controls(i).FontSize = Ctrl(i).FontSize * (ParentSH /
Ctrl(i).ParentHeight)
If Me.Controls(i).FontSize < 8 Then Me.Controls(i).FontSize = 8
If Me.Controls(i).FontSize > 12 Then Me.Controls(i).FontSize = 12
End If