i have been working on resize code for my vb6 project to adapt the forms to any screen size, and I pretty much got it thanks to this code from ark, which i adapted some, one thing I noticed though, it doesn't account for the task bar being different sizes, how can I do that? Measure the size and location of the taskbar and take that into consideration when resizing my forms?
The whole code piece
========Bas module code==========
Public Type CTRL_SIZE
ctWidth As Long
ctHeight As Long
End Type
Public Sub ResizeControls(frmParent As Form, Pos_Prev As CTRL_SIZE, Pos_New As CTRL_SIZE)
Dim fontRatio As Double
If frmParent.WindowState = vbMinimized Then
Pos_New = Pos_Prev
Exit Sub
End If
bFromCode = True
On Error Resume Next
Dim RatioX As Double, RatioY As Double
RatioX = Pos_New.ctWidth / Pos_Prev.ctWidth
RatioY = Pos_New.ctHeight / Pos_Prev.ctHeight
SendMessage frmParent.hWnd, WM_SETREDRAW, False, ByVal 0&
For Each ctrl In frmParent.Controls
ctrl.Left = Int(ctrl.Left * RatioX)
ctrl.Top = Int(ctrl.Top * RatioY)
ctrl.Width = Int(ctrl.Width * RatioX)
ctrl.Height = Int(ctrl.Height * RatioY)
fontRatio = RatioY
' or If RatioX > RatioY Then fontRatio = RatioY Else fontRatio = RatioX
If fontRatio = 0 Then fontRatio = 1
ctrl.FontSize = ctrl.FontSize * fontRatio
Next
On Error GoTo 0
SendMessage frmParent.hWnd, WM_SETREDRAW, True, ByVal 0&
frmParent.Refresh
End Sub
'=======Any form code========
Dim frmSize As CTRL_SIZE
Private Sub Form_Load()
'.................
frmSize.ctWidth = ScaleWidth
frmSize.ctHeight = ScaleHeight
End Sub
Private Sub Form_Resize()
Dim NewSize As CTRL_SIZE
NewSize.ctWidth = ScaleWidth
NewSize.ctHeight = ScaleHeight
ResizeControls Me, frmSize, NewSize
frmSize = NewSize
End Sub
Start Free Trial