taylorrr
asked on
Resizing controls on a form...
Hello,
I was wondering if anyone has got some code that will resize controls on a form when the form itself is
resized.
thx,
I was wondering if anyone has got some code that will resize controls on a form when the form itself is
resized.
thx,
First previous link is not useful.
http://www.vb-helper.com/howto_resize_controls_to_fit.html
https://www.experts-exchange.com/questions/20436275/Easy-Resize-Controls.html
http://www.vb-helper.com/howto_resize_controls_to_fit.html
https://www.experts-exchange.com/questions/20436275/Easy-Resize-Controls.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi
Open a form and put some controls on it.
Open a Module and put the code module on It.
Put the Code in form Code.
Run project and wash all the controls.
Module:
Option Explicit
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
Global Ctrl() As ScaleStruct
Code:
Option Explicit
Dim N
Private Sub Form_Load()
On Error Resume Next
ReDim Ctrl(0 To Controls.Count - 1)
For N = 0 To Controls.Count - 1
Ctrl(N).Top = Controls(N).Top
Ctrl(N).Left = Controls(N).Left
Ctrl(N).Width = Controls(N).Width
Ctrl(N).Height = Controls(N).Height
Ctrl(N).ParentHeight = Controls(N).Parent.ScaleHe ight
Ctrl(N).ParentWidth = Controls(N).Parent.ScaleWi dth
Ctrl(N).FontSize = Controls(N).FontSize
Next N
Me.Top = Screen.Height / 2 - Me.Height / 2
Me.Left = Screen.Width / 2 - Me.Width / 2
End Sub
Private Sub Form_Resize()
On Error Resume Next
For N = 0 To Controls.Count - 1
Controls(N).Visible = False
Controls(N).Top = Ctrl(N).Top * (Controls(N).Parent.ScaleH eight / Ctrl(N).ParentHeight)
Controls(N).Left = Ctrl(N).Left * (Controls(N).Parent.ScaleW idth / Ctrl(N).ParentWidth)
Controls(N).Width = Ctrl(N).Width * (Controls(N).Parent.ScaleW idth / Ctrl(N).ParentWidth)
Controls(N).Height = Ctrl(N).Height * (Controls(N).Parent.ScaleH eight / Ctrl(N).ParentHeight)
Controls(N).FontSize = Ctrl(N).FontSize * (Controls(N).Parent.ScaleH eight / Ctrl(N).ParentHeight)
If Controls(N).FontSize < 4 Then Controls(N).FontSize = 4
Controls(N).Visible = True
Next N
End Sub
Hope it Suites you.
Open a form and put some controls on it.
Open a Module and put the code module on It.
Put the Code in form Code.
Run project and wash all the controls.
Module:
Option Explicit
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
Global Ctrl() As ScaleStruct
Code:
Option Explicit
Dim N
Private Sub Form_Load()
On Error Resume Next
ReDim Ctrl(0 To Controls.Count - 1)
For N = 0 To Controls.Count - 1
Ctrl(N).Top = Controls(N).Top
Ctrl(N).Left = Controls(N).Left
Ctrl(N).Width = Controls(N).Width
Ctrl(N).Height = Controls(N).Height
Ctrl(N).ParentHeight = Controls(N).Parent.ScaleHe
Ctrl(N).ParentWidth = Controls(N).Parent.ScaleWi
Ctrl(N).FontSize = Controls(N).FontSize
Next N
Me.Top = Screen.Height / 2 - Me.Height / 2
Me.Left = Screen.Width / 2 - Me.Width / 2
End Sub
Private Sub Form_Resize()
On Error Resume Next
For N = 0 To Controls.Count - 1
Controls(N).Visible = False
Controls(N).Top = Ctrl(N).Top * (Controls(N).Parent.ScaleH
Controls(N).Left = Ctrl(N).Left * (Controls(N).Parent.ScaleW
Controls(N).Width = Ctrl(N).Width * (Controls(N).Parent.ScaleW
Controls(N).Height = Ctrl(N).Height * (Controls(N).Parent.ScaleH
Controls(N).FontSize = Ctrl(N).FontSize * (Controls(N).Parent.ScaleH
If Controls(N).FontSize < 4 Then Controls(N).FontSize = 4
Controls(N).Visible = True
Next N
End Sub
Hope it Suites you.
www.freevbcode.com/ShowCode.Asp?ID=4332