I have various picture sizes 800x600, 640x480... is there a way to shrink and expand them automatically to fit the image box I create on a form?
Printable View
I have various picture sizes 800x600, 640x480... is there a way to shrink and expand them automatically to fit the image box I create on a form?
Size your image box and set STRETCH property to true
DocZaf
{;->
If i set it to stretch some o fthe thinner pics lok very distorted? Can I stretch it to fit the box, center the picture in the box, and keep it porportional to the box that it is in?
Hi. You can look at this code. Make a form and a imagebox in it. You can now resize the form but the propotions are right.
Private Sub Form_Resize()
Image1.Width = Me.ScaleWidth
Image1.Height = Me.ScaleHeight
ScaleImage
End Sub
Public Sub ScaleImage()
Dim intDelen, intDelen2
If Image1.Picture.Width = 0 And Image1.Picture.Height = 0 Then Exit Sub
intDelen = 0
intDelen2 = 0
If Me.ScaleWidth < (Image1.Picture.Width / 2) Or Me.ScaleHeight < (Image1.Picture.Height / 2) Then
intDelen = ((Image1.Picture.Width / 2) - Me.ScaleWidth) / (Image1.Picture.Width / 2)
intDelen2 = ((Image1.Picture.Height / 2) - Me.ScaleHeight) / (Image1.Picture.Height / 2)
If intDelen >= intDelen2 Then
Image1.Width = (Image1.Picture.Width / 2) * (1 - intDelen)
Image1.Height = (Image1.Picture.Height / 2) * (1 - intDelen)
Else
Image1.Height = (Image1.Picture.Height / 2) * (1 - intDelen2)
Image1.Width = (Image1.Picture.Width / 2) * (1 - intDelen2)
End If
Else
Image1.Width = (Image1.Picture.Width / 2)
Image1.Height = (Image1.Picture.Height / 2)
End If
Image1.Top = (frmImage.ScaleHeight / 2) - (Image1.Height / 2)
Image1.Left = (frmImage.ScaleWidth / 2) - (Image1.Width / 2)
End Sub
thanks for the code, is there any way that it can be modified so that it automatically sizes the picture to fit in the screen, and the user does not have the ability to resize the screen.
It might not be the shortest number of code lines
but it isn't difficult to see whats going on
myform.top=0
myform.left=0
myform.width=screen.width
myform.height=screen.height
'taking it for granted that
'the border is double or sizable
myimage.width=(myform.width-120)
myimage.height=myform.height-420
myimage.stretch=true
load picture
DocZaf
{;->
Use my code and add this
Private Sub Form_Load()
Me.Width = Screen.Width
Me.Hight = Scree.Hight
Form_Resize
End Sub
Now will the picturebox be adjust to the screen, and to the user so It shall not me resizeable just set the Form properties BorderStyle to 1 or 3 (depends if you want to use the Maximum and Minimum bottons).