Public Class Form1
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
'I have used this timer to simulate the pictures being add to your flow layout panel
Static Counter As Integer
'firstly create a SINGLE instance of the class that is going to hold all the details
'that you want to save in the ta property of the picture
'See the class myTagDetails defined below to hold the information for the tag
Dim myTagInfo As New myTagDetails
With myTagInfo
.PicName = "Sample Pic"
.PicSize = 1000
.TimeAdded = Now()
.OtherImages.Add("Pic1")
.OtherImages.Add("Pic2")
End With
'Now create the pciturebox for the new image and set whatever properties you need
'finally add the myTagInfo variable to the tag property. Remember this is a single
'instance of the class but it has multiple properties
Dim PicBox As New PictureBox
With PicBox
.Name = "PictureBox" & Counter
.Image = My.Resources.BionatureLoginPic 'add your own picture here
.Width = 50
.Height = 50
.Tag = myTagInfo
End With
'add the picturebox to the flowlayoutpanel and add an event handler for the click event
flp.Controls.Add(PicBox)
AddHandler PicBox.Click, AddressOf PictureBoxClicked
End Sub
Private Sub PictureBoxClicked(sender As System.Object, e As System.EventArgs)
'so here is the event handler that is processed when each button is clicked
'The first this you see is that DirectCast is used to convert the sender object to type PictureBox
Dim ClickedPicBox As PictureBox = DirectCast(sender, PictureBox)
'Once we have got a Valid PictureBox type we can then convert the tag property which is now an object to its correct type
'bring type myTagDetails using the same principal as above
Dim PicTagDetails As myTagDetails = DirectCast(ClickedPicBox.Tag, myTagDetails)
'now that we have two corrected typed variables we can now do whatever we want with the selected picturebox.
MsgBox(PicTagDetails.PicName)
MsgBox(PicTagDetails.PicSize)
MsgBox(PicTagDetails.TimeAdded)
End Sub
Private Class myTagDetails
'Here we define a class that has multiple properties tht be be set as needed
'any variable type can be used here to do whatever you want
Public Property PicName As String
Public Property PicSize As Integer
Public Property TimeAdded As DateTime
Public Property OtherImages As New List(Of String)
End Class
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'flp is your flow layout panel
For Each myControl As Control In flp.Controls
If myControl.GetType = GetType(PictureBox) Then
Dim curPic As PictureBox = DirectCast(myControl, PictureBox)
Dim mytagInfo As myTagDetails = DirectCast(curPic.Tag, myTagDetails)
With mytagInfo
.OtherImages.Add("Pic1")
.OtherImages.Add("Pic2")
.OtherImages.Add("Pic3")
End With
End If
Next
End Sub
End Class