Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resizing a Form

Status
Not open for further replies.

tmcain

Programmer
Jan 29, 2002
25
0
0
US
I need to ensure that when a user resizes my form all the controls are still visible and in proportion.
Is there an easy way to do this?
If you can post examples, I would appreciate it.
Thanks
 
on Form_resize
control.hieght= change hieght relative to form.
control.witdh=
control.top
control.left

hope this helps. sorry for spelling. -God Bless
 
haven't tested on all controls and on controls containing other controls (i.e., Frames)

best i could come up with quickly

Code:
Option Explicit

Private Enum MVArgs
  MVLEFT
  MVTOP
  MVWIDTH
  MVHEIGHT
End Enum

Private Sub Form_Load()
  Dim oCtrl As Control
  
  ScaleHeight = 100
  ScaleWidth = 100
  
  For Each oCtrl In Controls
    With oCtrl
      .Tag = .Left & ", " & .Top & ", " & .Width & ", " & .Height
    End With
  Next oCtrl
End Sub

Private Sub Form_Resize()
  Dim oCtrl As Control
  Dim sVals() As String
  Dim nSW As Long
  Dim nSH As Long
  
  nSW = ScaleWidth
  nSH = ScaleHeight
  
  If WindowState = vbMinimized Then Exit Sub
  
  For Each oCtrl In Controls
    sVals = Split(oCtrl.Tag, ", ")
    oCtrl.Move Val(sVals(MVLEFT)) * nSW / 100, _
               Val(sVals(MVTOP)) * nSH / 100, _
               Val(sVals(MVWIDTH)) * nSW / 100, _
               Val(sVals(MVHEIGHT)) * nSH / 100
  Next oCtrl
End Sub
 
Option Explicit

' does not work for Image, Line, and Shape controls

Private mnHeight As Long
Private mnWidth As Long

Private Enum MVArgs
MVLEFT
MVTOP
MVWIDTH
MVHEIGHT
MVFONTSIZE
End Enum

Private Sub Form_Load()
Dim oCtrl As Control

On Error Resume Next

mnHeight = Height
mnWidth = Width

ScaleHeight = 100
ScaleWidth = 100

For Each oCtrl In Controls
With oCtrl
.Tag = .Left & ", " & .Top & ", " & .Width & ", " & .Height & ", " & .FontSize
End With
Next oCtrl

On Error GoTo 0
End Sub

Private Sub Form_Resize()
Dim oCtrl As Control
Dim sVals() As String
Dim nSW As Long
Dim nSH As Long

On Error Resume Next

nSW = ScaleWidth
nSH = ScaleHeight

If WindowState = vbMinimized Then Exit Sub

For Each oCtrl In Controls
With oCtrl
sVals = Split(oCtrl.Tag, ", ")
Select Case TypeName(oCtrl)
Case "DriveListBox", "ComboBox"
.Left = Val(sVals(MVLEFT)) * nSW / 100
.Top = Val(sVals(MVTOP)) * nSH / 100
.Width = Val(sVals(MVWIDTH)) * nSW / 100
.Height = Val(sVals(MVHEIGHT)) * nSH / 100
Case Else
.Move Val(sVals(MVLEFT)) * nSW / 100, _
Val(sVals(MVTOP)) * nSH / 100, _
Val(sVals(MVWIDTH)) * nSW / 100, _
Val(sVals(MVHEIGHT)) * nSH / 100
End Select
.FontSize = Val(sVals(MVFONTSIZE)) * nSH / 100
End With
Next oCtrl

On Error GoTo 0
End Sub

Private Sub mnuRestore_Click()
WindowState = vbNormal
Height = mnHeight
Width = mnWidth
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top