Main Topics
Browse All TopicsI have a form which the user opens on click of a button, once the form is opened If user try to resize the form while havin the application running. how do we do the following
Resize a form based on the user drag
Resize the controls on the form based on the form size
Resize the font size of all controls based on the above 2 items
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I've explained pretty clearly the algorithm for implementing this. No, I don't usually write complete working samples. I can give you a little pseudocode to get you started though:
Dim Textbox1 as Textbox ' or a textbox that is already dropped onto the form
Dim Textbox1_WidthRatio as Double
Dim Textbox1_HeightRatio as Double
Dim Textbox1_LeftRatio as Double
Dim Textbox1_TopRatio as Double
Sub Form1_Load(...)
' this is the onload event of the form
' determine the initial ratios
Textbox1_WidthRatio = Textbox1.Width / Form1.Width
Textbox1_HeightRatio = Textbox1.Height / Form1.Height
Textbox1_LeftRatio = Textbox1.Left / Form1.Width
Textbox1_TopRatio = Textbox1.Top / Form1.Height
.... repeat for other form objects ...
End Sub
Sub Form1_Resize()
' this is the resize event of the form. resize the textbox according to ratios
Textbox1.Width = Form1.Width * Textbox1_WidthRatio
Textbox1.Height = Form1.Height * Textbox1_HeightRatio
Textbox1.Top = Form1.Top * Textbox1_TopRatio
Textbox1.Left = Form1.Left * Textbox1_LeftRatio
... repeat for other form objects ...
End Sub
Forsty thank for the pseudocode, two things which i have to mention, firstly i have a code for resizing the form which resize the form only not the controls inside the form, please see the code below. Secondly in the below code where do i call the logic to resize the control when form is getting resized. I tried calling the control resize logic on m_objResizer_MouseMove but the control does not get resized rather it disappears. The control resize logic (ResizeControls) is at the end.
Option Explicit
Private Const MResizer = "ResizeGrab"
Private WithEvents m_objResizer As MSForms.Label
Private m_sngLeftResizePos As Single
Private m_sngTopResizePos As Single
Private m_blnResizing As Single
Private Sub m_AddResizer()
'
' add resizing control to bottom righthand corner of userform
'
Set m_objResizer = Me.Controls.Add("Forms.lab
With m_objResizer
With .Font
.Name = "Marlett"
.Charset = 2
.Size = 14
.Bold = True
End With
.BackStyle = fmBackStyleTransparent
.AutoSize = True
.BorderStyle = fmBorderStyleNone
.Caption = "o"
.MousePointer = fmMousePointerSizeNWSE
.ForeColor = RGB(100, 100, 100)
.ZOrder
.Top = Me.InsideHeight - .Height
.Left = Me.InsideWidth - .Width
End With
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub m_objResizer_MouseDown(ByV
If Button = 1 Then
m_sngLeftResizePos = X
m_sngTopResizePos = Y
m_blnResizing = True
End If
End Sub
Private Sub m_objResizer_MouseMove(ByV
If Button = 1 Then
With m_objResizer
.Move .Left + X - m_sngLeftResizePos, .Top + Y - m_sngTopResizePos
Me.Width = Me.Width + X - m_sngLeftResizePos
Me.Height = Me.Height + Y - m_sngTopResizePos
.Left = Me.InsideWidth - .Width
.Top = Me.InsideHeight - .Height
End With
End If
Call ResizeControls(Me, Me.height, Me.width)
End Sub
Private Sub m_objResizer_MouseUp(ByVal
If Button = 1 Then
m_blnResizing = False
End If
End Sub
Private Sub UserForm_Initialize()
m_AddResizer
Call GetLoc(Me, Me.height, Me.width)
End Sub
Private Sub UserForm_Terminate()
Me.Controls.Remove MResizer
End Sub
Control resize code starts here
--------------------------
Private List() As Control
Private iHeight As Integer
Private iWidth As Integer
Private x_size As Double
Private y_size As Double
Private Type Control
Indx As Integer
Name As String
Left As Integer
Top As Integer
width As Integer
height As Integer
End Type
Public Sub ResizeControls(frm As UserForm, height As Integer, width As Integer)
Dim i As Integer
x_size = height / iHeight
y_size = width / iWidth
'Loop though all the objects on the form
'Based on the upper bound of the # of controls
Dim ctl As Object
For i = 0 To UBound(List)
'Grad each control individually
For Each ctl In frm.Controls
'resize the control
With ctl
.Left = List(i).Left * y_size
.width = List(i).width * y_size
.height = List(i).height * x_size
.Top = List(i).Top * x_size
End With
'Get the next control
Next ctl
Next i
End Sub
Public Sub GetLoc(frm As UserForm, height As Integer, width As Integer)
Dim i As Integer
' Load the current positions of each object into a user defined type array.
' This information will be used to rescale them in the Resize function.
'Loop through each control
Dim ctl As Object
For Each ctl In frm.Controls
'Resize the Array by 1, and preserve
'the original objects in the array
ReDim Preserve List(i)
With List(i)
.Name = ctl.Name
.Left = ctl.Left
.Top = ctl.Top
.width = ctl.width
.height = ctl.height
End With
i = i + 1
Next ctl
iHeight = height
iWidth = width
End Sub
Business Accounts
Answer for Membership
by: Frosty555Posted on 2009-09-22 at 15:03:13ID: 25398050
The first part is done for you. When the user resizes the form windows will take care of actually sizing the form, and triggering Resize events on the form.
You can resize the controls on the form if you specify the controls sizes as a percentage of the size of the form. You can't do this directly, but when the form first loads, have some code look at the size of all the objects on the form and save the ratio of their size to the form size. When the form is resizes, hook into the resize event and have your code resize all the others controls using that same ratio you saved earlier.
Resizing the font is tricky because you can't quite determine exactly the size of the font. Fonts are displayed using the point size notation, so you can't resize it precisely. You can scale the font size up in the resize event of the form just like all the other controls but it will take some fiddling to get the fonts to not get too big or too small when you change the form size. The point size is not linearly related to the pixel size of fonts, you'll need to do some trial-and-error to get it looking just right.