Adjusting Form's Size

Posted on 2004-11-25
Last Modified: 2012-05-05
I have a PictureBox that gets loaded dynamically. Sometimes this ends up making the picture get trimmed. I'd like to adjust the form based on the size of this picture. How do I do this? I'm a little confused as to what values I should use .width, .scalewidth, etc.

Question by:tim8w
    LVL 8

    Accepted Solution

    Set both the picturebox and forms ScaleModes to Pixel (3)

    Then on Picture1_Change() do:

    Form1.Width = Picture1.Width * Screen.TwipsPerPixelX + 100
    Form1.Height = Picture1.Height * Screen.TwipsPerPixelY + 400

    Form1.Width = Picture1.Width * Screen.TwipsPerPixelX        { This is almost exact                           }
    Form1.Height = Picture1.Height * Screen.TwipsPerPixelY the {+400/100 is to make it a bit more exact}

    Author Comment

    Thanks. That worked great. Is there anyway to know what the height of the title bar is?

    LVL 8

    Expert Comment

    Private Sub Command1_Click()
        Dim TitleInfo As TITLEBARINFO
        TitleInfo.cbSize = Len(TitleInfo)
        GetTitleBarInfo Me.hwnd, TitleInfo
        Debug.Print "Title bar rectangle:"
        With TitleInfo.rcTitleBar
                MsgBox .Bottom - .Top
        End With
    End Sub

    Option Explicit

    Private Const CCHILDREN_TITLEBAR = 5
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Private Type TITLEBARINFO
        cbSize As Long
        rcTitleBar As RECT
        rgstate(CCHILDREN_TITLEBAR) As Long
    End Type
    Private Declare Function GetTitleBarInfo Lib "user32.dll" (ByVal hwnd As Long, ByRef pti As TITLEBARINFO) As Long

    That will message box the titlebar height. However, I think it should remain the same (19). Yet, maybe


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now