Adjusting Form's Size

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.

Thanks,
Tim
tim8wAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

List244Commented:
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}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tim8wAuthor Commented:
List244,
Thanks. That worked great. Is there anyway to know what the height of the title bar is?

Thanks,
Tim
0
List244Commented:
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
not.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.