by Ubeimar Alonso Vergara (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 21st December 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Resize controls in a form, when Maximize.
API Declarations
Public Ancho As Integer
Public Alto As Integer
Public AnchoActual As Integer
Public AltoActual As Integer
Public Maximizada As Boolean
'In LOAD event of the Form
Ancho = Me.Width
Alto = Me.Height
AnchoActual = Me.Width
AltoActual = Me.Height
Maximizada = False
'Or direct values, example: Ancho = 6000
'On RESIZE event of the Form
Call ValidarDimension Me
Public Sub ValidarDimension(Forma As Form)
On Error Resume Next
With Forma
If .WindowState <> vbMinimized Then
If .WindowState = vbMaximized Then
.Maximizada = True
RedimensionarForma Forma
ElseIf .WindowState = vbNormal Then
If .Maximizada Then RedimensionarForma Forma
.Height = .Alto
.Width = .Ancho
.Maximizada = False
Exit Sub
End If
End If
End With
End Sub
Public Sub RedimensionarForma(Forma As Form)
Dim FactorX As Double
Dim FactorY As Double
Dim FactorFuente As Double
Dim Indice As Integer
Dim I As Integer
FactorX = Forma.Width / Forma.AnchoActual
FactorY = Forma.Height / Forma.AltoActual
FactorFuente = (FactorX + FactorY) / 2
With Forma
For Indice = 0 To .Count - 1
.Controls(Indice).Left = .Controls(Indice).Left * FactorX
.Controls(Indice).Top = .Controls(Indice).Top * FactorY
.Controls(Indice).Width = .Controls(Indice).Width * FactorX
If Not TypeOf .Controls(Indice) Is ComboBox Then
.Controls(Indice).Height = .Controls(Indice).Height * FactorY
End If
If TypeOf .Controls(Indice) Is MSFlexGrid Then
For I = 0 To .Controls(Indice).Cols - 1
.Controls(Indice).ColWidth(I) = .Controls(Indice).ColWidth(I) * FactorX
Next
End If
.Controls(Indice).FontSize = .Controls(Indice).FontSize * FactorFuente
Next
End With
Forma.AnchoActual = Forma.Width
Forma.AltoActual = Forma.Height
End Sub