How to detect the resolution and control the size of a Form?

Posted on 2007-08-08
Last Modified: 2010-04-30
Hello group,

I'm using VB 6.0 for a project which creates a dialog (form) in Excel environment. However,  When the resolution changes by user, I want it to keep its size (height and width) in an appropriate.

How can I do this?

Question by:akohan
    LVL 53

    Assisted Solution

    LVL 53

    Assisted Solution

    How To Create a Resolution-Independent Form
    LVL 2

    Accepted Solution

    First you have to continuously monitor for is there any change in the resoulation. To find it out you can use following Win32 API Calls. When your program starts store these setings somewhere in your code using variables. After that start a thread (You can use Timer) which will fire these Win32 API calls and read current screen resoulation. Compare this information with you have initially. If there is any change, replace initial resoulation information with the new one and resize the form.

    Public Declare Function GetDeviceCaps Lib "gdi32" _
       (ByVal hdc As Long, _
        ByVal nIndex As Long) As Long

    Dim currHRes As Long
    Dim currVRes As Long
    Dim currBPP As Long

    currHRes = GetDeviceCaps(hdc, HORZRES)
       currVRes = GetDeviceCaps(hdc, VERTRES)
       currBPP = GetDeviceCaps(hdc, BITSPIXEL)

    For Sample code, try this link:

    Best Luck


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now