[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

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
0
tim8w
Asked:
tim8w
  • 2
1 Solution
 
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
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now