Here you go .. ..
Inputs: Filepath (The path of the image to load)
Returns: None
Assumes: Create a new form (in my example: frmMain), Place a picturebox control on that form, name it picStart. Set picStart.Autosize to TRUE. Set picStart.Visible to FALSE. Create another picturebox on the form called picMain. This will be the picturebox that determins the final size of your image. Set picMain.Autosize to False. Create an Image Object *INSIDE* the picturebox control. Name the image control imgMain. Set ingMain.Stretch to TRUE.
Side Effects: NONE
**************************
Private Sub LoadImage(filePath As String)
Dim X As Long
Dim Y As Long
With frmMain
.imgMain.Visible = False
.picStart.Picture = LoadPicture(filePath)
X = .picStart.Width
Y = .picStart.Height
If X > .picMain.Width Then
X = .picMain.Width
End If '»If X > .picMain.Width Then
If Y > .picMain.Height Then
Y = .picMain.Height
End If '»If Y > .picMain.Height Then
.imgMain.Width = X
.imgMain.Height = Y
' *** center the picture
.imgMain.Top = (.picMain.Height \ 2) - (.imgMain.Height \ 2)
.imgMain.Left = (.picMain.Width \ 2) - (.imgMain.Width \ 2)
' *** now copy the image from the start picbox(picstart) into the
' display image field (imgMain)
.imgMain.Picture = .picStart.Picture
.imgMain.Visible = True
End With '»With frmMain
End Sub
**************************
Regards, John vb_doc@hotmail.com
Main Topics
Browse All Topics





by: TomLaw1999Posted on 2002-06-06 at 11:37:18ID: 7060055
Have you considered using an image instead of a picture box.