I have an image control on my form and I want the picture to change based on certain events. Let's say there are four different possible images. I know that I can set the control to whatever image I want using:
imgBox1.Picture = LoadPicture(sPath & "img1.bmp")
But I guess my question really is, do I have to use the LoadPicture function every time I want to change imgBox1 to a different picture (say, "img2.bmp")? Or can I load the four different images to some kind of object and then just set imgBox1.Picture to equal that object? I've tried several different ways and can't get anything to work.
StdPicture is the type to use to store an image.
The example below loads 3 images from disk once then cycles them on a button click.
Private mPics(2) As StdPicture
Private mIndex As Long
Private Sub Form_Load()
Set mPics(0) = LoadPicture("C:\kitty_born.bmp")
Set mPics(1) = LoadPicture("C:\kitty_life.bmp")
Set mPics(2) = LoadPicture("C:\kitty_dead.bmp")
End Sub
Private Sub someButton_Click()
If mIndex > UBound(mPics) Then mIndex = 0
Set somePictureOrImageBox.Picture = mPics(mIndex)
mIndex = (mIndex + 1)
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With