Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB6 - Load/store images to be used later

Tags:

image

vb6

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.

like image 397
glassy Avatar asked Dec 14 '25 02:12

glassy


1 Answers

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
like image 115
Alex K. Avatar answered Dec 15 '25 18:12

Alex K.