Dim myImage As Image
myImage = DirectCast(flp.Controls("Pic1"), PictureBox).Image
the name as in when you create the picturebox you put a name in picturebox.name ? hmm i thought i tried that. when i go flp.Controls("name").image , it always say image is not a member of control.
Dim totalFiles As Integer = e.UserState(0)
sender.image =img
bgwLoadImage.ReportProgress(i, {file.GetUpperBound(1), file(1, i), img, file(3, i), file(4, i), file(5, i)})
Dim totalFiles As Integer = CInt(DirectCast(e.UserState, Object())(0))
DirectCast(sender, PictureBox).Image = img
bgwLoadImage.ReportProgress(i, New Object() {file(0, i), file(1, i), img, file(3, i), file(4, i), file(5, i), file.GetUpperBound(1)})
tssl1.text = sender.tag(2).tostring
tssl1.text = CStr(DirectCast(sender, PictureBox).Tag)(2)
Dim img As Image = e.UserState(2)
Dim img As Image = DirectCast(DirectCast(e.UserState, Object())(2), Image)
tssl1.Text = sender.Tag(2)
tssl1.Text = DirectCast(sender, PictureBox).Tag(2).toString
tssl1.Text = DirectCast(DirectCast(sender, PictureBox).Tag, Object())(2).ToString
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 own 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 tag property of the picture box
'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()
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
'Firstly you will see 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 myTagDetails using the same principal as above
Dim PicTagDetails As myTagDetails = DirectCast(ClickedPicBox.Tag, myTagDetails)
'now that we have two correctly 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 that be changed and modified 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
End Class
End Class