Form and Picture Resizing 
Author Message
 Form and Picture Resizing

Hello,
I have a project including a form with a picturebox control with AuotSize
set to true.  I want the form to resize upon loading of a new picture, and I
used this simplistic code:

    Form1.Height = Picture1.Height
    Form1.Width = Picture1.Width

Of course, this is TOO simplistic, for the visible portion of the picture is
cropped by the width and height of the Caption bar and the form's menu.

My mind is on brainlock and would appreciate a tip on how to include the
extra necessary widths and heights.

Thank You,
John



Fri, 10 Nov 2000 03:00:00 GMT  
 Form and Picture Resizing

John-
        Here's some code from examples
I've posted in the past- for similar requests.
Hope this helps .
Joe
__________Snip__________________________
Option Explicit
Private Const FUDGEFACTOR = 0.95

Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then Unload Me
End Sub

Private Sub Form_Load()
    Dim Percent As Single
    Dim DesiredHeight As Long
    KeyPreview = True
    BackColor = vbBlack
    WindowState = vbMaximized
    DesiredHeight = Screen.Height
    With Image1
        .Visible = False
        .Stretch = False
        .Picture = LoadPicture("c:\naomi.jpg")
        If .Height <> DesiredHeight Then
            Percent = (DesiredHeight / .Height) * FUDGEFACTOR
            .Stretch = True
            .Height = CLng(.Height * Percent)
            .Width = CLng(.Width * Percent)
        End If
        .Visible = True
    .Move ((Screen.Width - .Width) / 2), (Screen.Height - .Height) / 2
    End With
End Sub

________Snip______________________________

Option Explicit

Private Const DESIREDHEIGHT = 2000

Private Sub Form_Load()
    Dim Percent As Single
    On Error GoTo OOPS
    With Image1
        .Visible = False
        .Stretch = False
        .Picture = LoadPicture("c:\naomi.jpg")
        If .Height <> DESIREDHEIGHT Then
            Percent = DESIREDHEIGHT / .Height
            .Stretch = True
            .Height = CLng(.Height * Percent)
            .Width = CLng(.Width * Percent)
        End If
        .Visible = True
    End With
Exit Sub
OOPS:
    MsgBox "What happened?"
End Sub
________snip______________________________________
--
***********************************************************

Microsoft Developer MVP- Visual Basic
VB geek at large. (Well, not that large!)
"He preaches well that lives well, quoth Sancho; that's
all the divinity I understand." Miguel de Cervantes
**********************************************************
PS- Please reply to the newsgroup- except in the
case of flames, insults, etc. (Don't bother.)



Quote:
> Hello,
> I have a project including a form with a picturebox control with AuotSize
> set to true.  I want the form to resize upon loading of a new picture,
and I
> used this simplistic code:

>     Form1.Height = Picture1.Height
>     Form1.Width = Picture1.Width

> Of course, this is TOO simplistic, for the visible portion of the picture
is
> cropped by the width and height of the Caption bar and the form's menu.

> My mind is on brainlock and would appreciate a tip on how to include the
> extra necessary widths and heights.

> Thank You,
> John



Fri, 10 Nov 2000 03:00:00 GMT  
 Form and Picture Resizing

Quote:

>Hello,
>I have a project including a form with a picturebox control with AuotSize
>set to true.  I want the form to resize upon loading of a new picture, and
I
>used this simplistic code:

>    Form1.Height = Picture1.Height
>    Form1.Width = Picture1.Width

>Of course, this is TOO simplistic, for the visible portion of the picture
is
>cropped by the width and height of the Caption bar and the form's menu.

>My mind is on brainlock and would appreciate a tip on how to include the
>extra necessary widths and heights.

>Thank You,
>John

There's a kludgy way that works also (along with the method posted).  I post
it only because it is simpler to code.

form.scalewidth and form.scaleheight return the dimensions of the client
area of the form, not including titlebar and borders.  Set form.scalemode =
vbtwips, and store the difference between the width and the scalewidth, and
the difference between the height and the scaleheight.  Then increase your
form size by that amount.  The code would be something like this:

dim fWidthDiff as single
dim fHeightDiff as single

form.scalemode = vbTwips
fWidthDiff = form.width - form.scalewidth
fHeightDiff = form.height - form.scaleheight

(resize picture, or whatever)

(in picture_resize event, probably)

form.height = picture.height + fHeightDiff
form.width = picture.width + fWidthDiff

I've used similar techniques before with success.  It may well be documented
that the scaled values return the client area of the control, but I
discovered it by accident.

HTH.

Geoff Douglass



Sat, 11 Nov 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. how resize a picture in ai MDI Form

2. Resize a form to fit a picture

3. autosize picture box and resize form

4. resize pictures on forms

5. Resizing Picture in Form

6. how resize a picture in a MDI Form

7. Help resizing a form window to exactly fit a picture

8. Resizing a picture box in an MDI form...

9. Dynamic Resizing of a form &control based on picture size

10. Resizing a picture box in an MDI form...

11. Resize Picture in Picture Box

12. resizing a picture in a picture box

 

 
Powered by phpBB® Forum Software