Question

resize form while havin the application running

Asked by: vrajvilas

I 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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-22 at 13:03:46ID24752909
Tags

VBA

Topics

VB Controls

,

VB Script

,

VB Objects

Participating Experts
2
Points
500
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Resizing a form
    How to resize a form depending on the resolution, so that all the components of the form have the same proportion as in the original size? Should I resize each component manually or there is another way? Maybe with PixelPerInch, but when I use it the form doesn't change? If t...
  2. items on form when resized
    how can i make the items on the form to resize to the size of the form when the form is resized in run time?
  3. Unable to resize form by dragging!
    Hi all, I am modifying a previously developed Delphi project. I am not able to resize the existing forms by simply dragging ends with the mouse pointer. But the form is resizing automatically when i place a button control on it and push it .Why is this? The files are not wri...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

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.

 

by: vrajvilasPosted on 2009-09-22 at 18:05:42ID: 25399234

If you can provide me with the code to do this that would be really helpfull. i cant use any outside tools in my application

 

by: VBClassicGuyPosted on 2009-09-23 at 07:35:46ID: 25403553

If no 3rd party controls allowed, then Frosty's answer is your only solution.

 

by: vrajvilasPosted on 2009-09-23 at 11:00:50ID: 25405994

Frostys can i get a complete working sample code of what you have written. that would be great, as i need to wind up this project your help is highl appreciated

 

by: vrajvilasPosted on 2009-09-23 at 14:15:14ID: 25408020

Is there any one who can give me a sample working code on VBA to

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

 

by: Frosty555Posted on 2009-09-23 at 22:48:56ID: 25410359

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

 

by: vrajvilasPosted on 2009-09-24 at 07:39:22ID: 25413802

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.label.1", MResizer, True)
    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(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

    If Button = 1 Then
        m_sngLeftResizePos = X
        m_sngTopResizePos = Y
        m_blnResizing = True
    End If
   
End Sub
Private Sub m_objResizer_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

    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 Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    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

 

by: vrajvilasPosted on 2009-09-24 at 17:07:26ID: 31632173

could be nice if some working sample could have been provided

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...