If you know what image you want to display during design time, you can simply click the ... next to the picture property, and select the image you want to display.
To load an image at run-time, you can use the Picture property, and the LoadPicture method:
Set PictureBox.Picture = LoadPicture(strFilePath)
Where PictureBox is the name of your PictureBox control, and strFilePath is the path of the image you want displayed.
The following formats are supported for loading:
Bitmaps (*.bmp;*.dib)
GIF Images (*.gif)
JPEG Images (*.jpg)
MetaFiles (*.wmf;*.emf)
Icons (*.ico;*.cur)
If you want to display an animated GIF file, then you can use this dll.
If you want the picture box to automatically resize to display the whole of the picture, then you can set its AutoSize property to True.
However, if the image will not fit onto the screen, or you do not want to take up the whole screen, you will need to add some scroll bars. This is more complicated than it should be. I think the best way is to use the VB Accelerator Flat Scroll bar control. Once you have downloaded it, create a new project. Then add the Flat Scroll Bar control, and name it scrPort. Select the control, and then add a Image control (we use the Image control, because we do not need the PictureBox's features. You could use one if you wanted to), and call that imgPic. Then add the following code:
Private Sub Form_Load()
'// set the path of the image
sPic = "D: oolbox.gif"
'// display the picture
Set imgPic.Picture = LoadPicture(sPic)
With scrPort
'// set the scroll bar properties
.ActiveBar = efstHorizontal
.Max = (imgPic.Width - scrPort.ScaleWidth)
Screen.TwipsPerPixelX
.LargeChange = scrPort.ScaleWidth
(Screen.TwipsPerPixelX * 2)
.SmallChange = 8
.ActiveBar = efstVertical
.Max = (imgPic.Height - scrPort.ScaleHeight)
Screen.TwipsPerPixelY
.LargeChange = scrPort.ScaleHeight
(Screen.TwipsPerPixelY * 2)
.SmallChange = 8
End With
'// Move the image to the edge of the control
imgPic.Move 0, 0
End Sub
Private Sub scrPort_Change()
Dim lL As Long
Dim lT As Long
With scrPort
.ActiveBar = efstHorizontal
lL = -1 * .Value * Screen.TwipsPerPixelX
.ActiveBar = efstVertical
lT = -1 * .Value * Screen.TwipsPerPixelY
End With
'// move the image
With imgPic
.Move lL, lT, .Width, .Height
End With
End Sub
Private Sub scrPort_Scroll()
scrPort_Change
End Sub
Comments