Results 1 to 7 of 7

Thread: Solution (Resolve) to resizing Form + Controls

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Newport Richey,Fla
    Posts
    11

    Talking Solution (Resolve) to resizing Form + Controls

    This Forum has been of great assistance to me. Here is
    something of value to contribute.

    'Found and copied from www.vbcode.com. Not mine, but
    'resizes perfectly, controls and all

    'Resolution Resize and Run Time Control Resize.
    'Module for automatically resizing forms and
    'controls with varying screen resolutions. This is
    'an adaptation of a Microsoft Knowledge Base
    'article. The example worked as it was but half the
    'code was on the form. I wanted a complete module
    'to add to any app easily. To use it simply add
    '"Call AdjustForm(Me)" to the Form_Load event
    'and "Call FormResize(Me)" to the Form_Resize
    'event. Also change the design time resolution
    'values, if needed. It is coded to 1024x768


    'Place in Module
    Option Explicit

    Public Xtwips As Integer, Ytwips As Integer
    Public Xpixels As Integer, Ypixels As Integer

    Type FRMSIZE
    Height As Long
    Width As Long
    End Type

    Public RePosForm As Boolean
    Public DoResize As Boolean
    Dim MyForm As FRMSIZE
    Dim DesignX As Integer
    Dim DesignY As Integer
    Dim ScaleFactorX As Single, ScaleFactorY As Single


    Sub Resize_For_Resolution(ByVal SFX As Single, ByVal SFY As Single, MyForm As Form)
    Dim I As Integer
    Dim SFFont As Single
    SFFont = (SFX + SFY) / 2
    On Error Resume Next
    With MyForm
    For I = 0 To .Count - 1
    If TypeOf .Controls(I) Is ComboBox Then
    .Controls(I).Left = .Controls(I).Left * SFX
    .Controls(I).Top = .Controls(I).Top * SFY
    .Controls(I).Width = .Controls(I).Width * SFX
    Else
    .Controls(I).Move .Controls(I).Left * SFX, _
    .Controls(I).Top * SFY, _
    .Controls(I).Width * SFX, _
    .Controls(I).Height * SFY
    End If
    .Controls(I).FontSize = .Controls(I).FontSize * SFFont
    Next I
    If RePosForm Then
    .Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY
    End If
    End With
    End Sub


    Public Sub FormResize(TheForm As Form)
    Dim ScaleFactorX As Single, ScaleFactorY As Single
    If Not DoResize Then
    DoResize = True
    Exit Sub
    End If
    RePosForm = False
    ScaleFactorX = TheForm.Width / MyForm.Width
    ScaleFactorY = TheForm.Height / MyForm.Height
    Resize_For_Resolution ScaleFactorX, ScaleFactorY, TheForm
    MyForm.Height = TheForm.Height
    MyForm.Width = TheForm.Width
    End Sub

    Public Sub AdjustForm(TheForm As Form)
    Dim Res As String ' Returns resolution of system
    ' Put the design time resolution in here
    DesignX = 1024
    DesignY = 768
    RePosForm = True
    DoResize = False
    Xtwips = Screen.TwipsPerPixelX
    Ytwips = Screen.TwipsPerPixelY
    Ypixels = Screen.Height / Ytwips
    Xpixels = Screen.Width / Xtwips
    ScaleFactorX = (Xpixels / DesignX)
    ScaleFactorY = (Ypixels / DesignY)
    TheForm.ScaleMode = 1
    Resize_For_Resolution ScaleFactorX, ScaleFactorY, TheForm
    Res = Str$(Xpixels) + " by " + Str$(Ypixels)
    Debug.Print Res
    MyForm.Height = TheForm.Height
    MyForm.Width = TheForm.Width

    End Sub
    'End Module

    'Place in form_Load
    Call AdjustForm(me)

    'Place in Form_Resize
    Call FormResize(me)

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    We are delighted that you've solved your problems (or at least some of them) but next time when you want to post a VB code use vbcode tags, so it would be readable.

    Cheers
    Roy

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Newport Richey,Fla
    Posts
    11

    Question vb code tags?

    Thanks for the tip, but I'm a little confused. If you let me know what you mean, or can direct me....I now see "See Forum Rules", and I'll go there. I was simply copying and pasting to make sure I got it all. I didn't know this was unreadable!

  4. #4
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    For vb related code use this: "vbcode" - prior to code and "/vbcode" right after. Just change quotes to square brackets. Click on the HELP link next to VB Code on the left hand side of your screen.
    Roy

  5. #5
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    You will see that when in "Reply" mode.
    Roy

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Whenever you needed to write quote in the forums, use the [vbcode][/vbcode] tags. For example:

    [vbcode]'Your code here[/vbcode]

    would look like this:

    VB Code:
    1. 'Your code here
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Newport Richey,Fla
    Posts
    11

    Thumbs up That seems simple enough

    OK. Thanks for the insight and tips. I'll try it next time...and I'll go to "Help" and review it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width