Hi All,

I've developed an application in VB6. All forms are designed at 1024X768 scren resolution. But when I open this application at lower or higher resolution all controls get disturbed. Any clue....

Dani AI

Generated

— this is the classic VB6 fixed‑layout problem: forms are placed at design time for one client size (your 1024×768) and controls use fixed coordinates, so changing resolution or DPI shifts or clips them. Thread suggestions (rebuild per resolution, force users to change resolution or install drivers) will work but are poor UX or maintenance-heavy; forcing a resolution can also change color depth and cause visual problems. (vb-helper.com)

A practical, maintainable solution is runtime scaling. Pattern: pick a baseline client size (the size you designed for), save every control’s original Left/Top/Width/Height and Font.Size once at startup, compute x/y scale factors from the current client area, then reposition/resize each control (and scale fonts) on Form_Load and Form_Resize. Handle container controls (Frames, PictureBoxes) by processing child controls recursively or by treating each container as its own scaling root. This is the standard approach used in VB6 examples. (vb-helper.com)

A compact implementation (store baseline then apply scale):

Option Explicit

Private Type CtlPos
    Left As Single
    Top As Single
    Width As Single
    Height As Single
    FontSize As Single
End Type

Private mBaseW As Single, mBaseH As Single
Private mOrig() As CtlPos
Private mInitDone As Boolean

Private Sub SaveBaseline()
    Dim i As Long, ctl As Control
    mBaseW = Me.ScaleWidth: mBaseH = Me.ScaleHeight
    ReDim mOrig(Me.Controls.Count - 1)
    i = 0
    For Each ctl In Me.Controls
        If Not TypeOf ctl Is Line Then
            mOrig(i).Left = ctl.Left
            mOrig(i).Top = ctl.Top
            mOrig(i).Width = ctl.Width
            mOrig(i).Height = ctl.Height
            On Error Resume Next
            mOrig(i).FontSize = ctl.Font.Size
            On Error GoTo 0
        End If
        i = i + 1
    Next
    mInitDone = True
End Sub

Private Sub Form_Load()
    SaveBaseline
    ResizeControls
End Sub

Private Sub Form_Resize()
    If Not mInitDone Then Exit Sub
    ResizeControls
End Sub

Private Sub ResizeControls()
    Dim sx As Double, sy As Double, i As Long
    Dim ctl As Control
    If WindowState = vbMinimized Then Exit Sub
    If mBaseW = 0 Or mBaseH = 0 Then Exit Sub
    sx = ScaleWidth / mBaseW: sy = ScaleHeight / mBaseH
    i = 0
    For Each ctl In Me.Controls
        If Not TypeOf ctl Is Line Then
            ctl.Left = CLng(mOrig(i).Left * sx)
            ctl.Top = CLng(mOrig(i).Top * sy)
            ctl.Width = CLng(mOrig(i).Width * sx)
            If Not (TypeOf ctl Is ComboBox) Then ctl.Height = CLng(mOrig(i).Height * sy)
            On Error Resume Next
            ctl.Font.Size = mOrig(i).FontSize * ((sx + sy) / 2)
            On Error GoTo 0
        End If
        i = i + 1
    Next
End Sub

Notes and caveats: some controls (ComboBox height, certain third‑party controls) don’t resize the way others do; labels with AutoSize set can reflow; pictures need explicit stretch/zoom handling. Test at multiple DPI and resolutions and treat each frame/picturebox as its own container (use the control’s Container property when needed). If you must support many radically different layouts, consider a small anchoring/resizer component or migrating forms to a UI framework that supports fluid layouts. Avoid programmatically forcing the user’s desktop resolution except as an absolute last resort. (vb-helper.com)

Recommended Answers

All 9 Replies

Hi All,

I've developed an application in VB6. All forms are designed at 1024X768 scren resolution. But when I open this application at lower or higher resolution all controls get disturbed. Any clue....

Clue? Well, you have developed all your forms to run in high resolution screen. Then why you balme VB6. You instruct your Users to swith over to High resolution graphic addapters for their monitors.
or if they have, they should install the drivers for this. eg Intel(R) Extreme Graphic and select your 1024x768 resolution.

Dear AV Manoharan,

I can't tell to my users to switch to higher resolution, but my application should be such that it should work for all resolution. If you have any idea about it then please contribute. I've already downloaded some controls but that are not upto the mark (it does not manage control within frame).

Sorry, I couldn't visualize your problem. Could you post some screenshots please?

Hi Shrini,

To Create a Screen Resolution-Independent form, Check this Link from M$ Here :

Regards
Veena

Hi Shrini,

To Create a Screen Resolution-Independent form, Check this Link from M$ Here :

Regards
Veena

Dear AV Manoharan,

I can't tell to my users to switch to higher resolution, but my application should be such that it should work for all resolution. If you have any idea about it then please contribute. I've already downloaded some controls but that are not upto the mark (it does not manage control within frame).

Shrini, It is the drawback of every new technology. We can have upward compatibility to an extend. But seldom downward compatiblity. You have two choices. One is simple. Recereate all your forms with lower resolution. The other is at the program load time you have to ascertain in which resolution the user works. Accordingly you have to load the forms seperately created to work on those resolutions. I do not know yet that there are controls to change the resolution of a display object. Even if it is there how it acsertain the User's resolution implicitly? If you come accross such a thing please send me a message.

Thanks
AV Manoharan

Hello Veena,

Thanks for reply. I visisted the link and tried but it is clearly mentioned that design the form in 800X600 resolution. I've developed my application in 1024X768 resolution. It doesn't work perfectly at lower resolution.

Regards,
Shrinivas.

Hi Shrini,

To Create a Screen Resolution-Independent form, Check this Link from M$ Here :

Regards
Veena

Hi Srini,

As mentioned in the Link above,
it is always a good idea to design the form in Lower Resolution and then resize for higher ones.
If u do the Reverse way, u can still do it, change this :
DesignX = 1024
DesignY = 768
But the SCreen would look too distorted..
Next time when u do a new Form Design, just follow this Rule..

Regards
Veena

Hi Kshrini,

One way you can apply to solve your problem. You can design your application in such a way that it should check the resolution that has been currently set in user's computer. If it is 1024*768 then you allow the user to run the application otherwise you can display a notification msg to the user and change the resolution back to 1024*768. Yes, it is possible to change the resolution to 1024*768 through code. If you wish I can send you the code. Just send a mail to me at the following address :-

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.