Listbox - Picturebox (VB6)

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Listbox - Picturebox (VB6)

Post by D Willett »

Hi

I have one Listbox with image path & filenames.
I have 4 picture boxes.

I want to fill each picture box with each selection from the listbox to a maximum of 4.

So if all picture box's are empty, on the first selection of the listbox picture1 will load the file selected. On the second selection of the listbox picture2 will load the file selected and so on. There needs to be a trap of 4 so the user cannot select more than 4.

Does anyone have any samples on this?

Kind Regards

( This also posted on VBForums )
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78528
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Listbox - Picturebox (VB6)

Post by HansV »

Perhaps something like this (it is air code since I don't have VB6). I have assumed that the list box is named ListBox1 and that the picture box controls are named PictureBox1, PictureBox2, PictureBox3 and PictureBox4.

Code: Select all

Private Sub ListBox1_Click()
    Dim i As Long
    For i = 1 To 4
        If Me.Controls("PictureBox" & i).Picture Is Nothing Then
            Me.Controls("PictureBox" & i).Picture = LoadPicture(Me.ListBox1)
            Exit For
        End If
    Next i
End Sub
The user could select the same picture more than once. To prevent that would be more complicated.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Listbox - Picturebox (VB6)

Post by D Willett »

Hi Hans

Thanks for the code. Haven't had chance to test yet but I'm sure it will be good.

Regards
Dave
Cheers ...

Dave.