Results 1 to 11 of 11

Thread: Resolution Independent Forms

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    1

    Resolution Independent Forms

    I am looking to display VB forms in a resolution independent environment.
    I can't create an array of controls that can be resized at design time as each control must be individually named.
    Is it possible to create a form that can be de displayed in all screen resolutions without having to code for the lowest common demoninator i.e. 640 * 480 display?
    Can forms be displayed on a screen with scroll bars like occurs for web pages within an Internet browser, i.e. it doesn't matter about the resolution of the screens as all text within the browser can be seen with the help of scroll bars?

  2. #2
    Frenzied Member JungleMan's Avatar
    Join Date
    Feb 2001
    Posts
    2,033
    could you tell us the purpose of your app? maybe we could help you a bit more
    I'm bringing geeky back...

  3. #3
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    resolution independent environment??

    Do you mean the controls would size to the screen size???
    I have a control that does it if you want.....

  4. #4
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    ' Taken from Microsoft Knowledgebase Article ID: Q182070
    ' 1) Change the video resolution to 800 x 600.
    ' 2) Start a new project in Visual Basic. Form1 is created by default.
    ' 3) Add a Label, a CommandButton, and any other types of controls you would like to test.
    ' Copy the following code into the Form's module:

    [CODE]
    Dim MyForm As FRMSIZE
    Dim DesignX As Integer
    Dim DesignY As Integer

    Private Sub Form_Load()
    Dim ScaleFactorX As Single, ScaleFactorY As Single ' Scaling factors
    ' Size of Form in Pixels at design resolution
    DesignX = 800
    DesignY = 600
    RePosForm = True ' Flag for positioning Form
    DoResize = False ' Flag for Resize Event
    ' Set up the screen values
    Xtwips = Screen.TwipsPerPixelX
    Ytwips = Screen.TwipsPerPixelY
    Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution
    Xpixels = Screen.Width / Xtwips ' X Pixel Resolution
    ' Determine scaling factors
    ScaleFactorX = (Xpixels / DesignX)
    ScaleFactorY = (Ypixels / DesignY)
    ScaleMode = 1 ' twips
    'Exit Sub ' uncomment to see how Form1 looks without resizing
    Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
    Label1.Caption = "Current resolution is " & Str$(Xpixels) + _
    " by " + Str$(Ypixels)
    MyForm.Height = Me.Height ' Remember the current size
    MyForm.Width = Me.Width
    End Sub

    Private Sub Form_Resize()
    Dim ScaleFactorX As Single, ScaleFactorY As Single
    If Not DoResize Then ' To avoid infinite loop
    DoResize = True
    Exit Sub
    End If

    RePosForm = False
    ScaleFactorX = Me.Width / MyForm.Width ' How much change?
    ScaleFactorY = Me.Height / MyForm.Height
    Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
    MyForm.Height = Me.Height ' Remember the current size
    MyForm.Width = Me.Width
    End Sub

    Private Sub Command1_Click()
    Dim ScaleFactorX As Single, ScaleFactorY As Single
    DesignX = Xpixels
    DesignY = Ypixels
    RePosForm = True
    DoResize = False
    ' Set up the screen values
    Xtwips = Screen.TwipsPerPixelX
    Ytwips = Screen.TwipsPerPixelY
    Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution
    Xpixels = Screen.Width / Xtwips ' X Pixel Resolution
    ' Determine scaling factors
    ScaleFactorX = (Xpixels / DesignX)
    ScaleFactorY = (Ypixels / DesignY)
    Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
    Label1.Caption = "Current resolution is " & Str$(Xpixels) + _
    " by " + Str$(Ypixels)
    MyForm.Height = Me.Height ' Remember the current size
    MyForm.Width = Me.Width
    End Sub

    ' 4) Add a Module from the Project menu and paste in the following code:

    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

    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 ' average scale
    ' Size the Controls for the new resolution
    On Error Resume Next ' for read-only or nonexistent properties
    With MyForm
    For I = 0 To .Count - 1
    If TypeOf .Controls(I) Is ComboBox Then ' cannot change Height
    .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
    ' Now size the Form
    .Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY
    End If
    End With
    End Sub
    [CODE]

  5. #5
    RobIII
    Guest
    Use an MDI interface, make all your forms Child forms and you're done

    To create one, click the Project Menu, select Add MDI form. Set all the MDIChile properties of each form to True and that's it...

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by RobIII
    Use an MDI interface, make all your forms Child forms and you're done

    To create one, click the Project Menu, select Add MDI form. Set all the MDIChile properties of each form to True and that's it...
    That's not true. If you create an extremely big form, you won't see the whole form on a smaller resolution.
    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
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    If you resize all the controls on the form at runtime, then it'll will be to resize according to the resolution unless you use - or + (eg A.Top = Me.ScaleHeight-3: this will move to control to 3 pixels less than the form's height no matter what the resolution is).
    Baaaaaaaaah

  8. #8
    RobIII
    Guest
    Originally posted by Mc Brain

    That's not true. If you create an extremely big form, you won't see the whole form on a smaller resolution.
    Okay, but you WILL see scrollbars and won't have to write ANY extra code for resizing:

    Can forms be displayed on a screen with scroll bars like occurs for web pages within an Internet browser, i.e. it doesn't matter about the resolution of the screens as all text within the browser can be seen with the help of scroll bars?"
    There you have it...

    Originally posted by abdul

    If you resize all the controls on the form at runtime, then it'll will be to resize according to the resolution unless you use - or + (eg A.Top = Me.ScaleHeight-3: this will move to control to 3 pixels less than the form's height no matter what the resolution is).
    Just to remind ya'll: VB works with TWIPS as default, NOT pixels

  9. #9
    New Member
    Join Date
    Sep 2001
    Posts
    13
    I didn't notice that to be true either. You still don't see the entire form...
    Are you frum?

    http://www.FrumForum.com

  10. #10
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by RobIII

    Just to remind ya'll: VB works with TWIPS as default, NOT pixels
    I was assuming you had set the screen mode to "Pixels". I always do that whenever I am performing this kind of operation.
    Baaaaaaaaah

  11. #11
    New Member
    Join Date
    Sep 2001
    Posts
    13
    Still doesn't do it... more details please...
    Are you frum?

    http://www.FrumForum.com

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