Maybe it's a noob question ... anyway, I create a dynamic number of PictureBox controls.
I keep them inside a List.
What I want now is to make them clickable: same event handler for all (opening of the image source file) with a parameter.
The question is: how can I do it in practice?
How I set the handler Sub for every picbox?
Thanks a lot

Private Sub MethodThatCreatesDynamicPictureBoxes()
   'Your code for dynamically creating picturebox
   AddHandler yourPicBox.Click, AddressOf picbox_Click
End Sub

Private Sub picbox_Click(ByVal sender As Object, ByVal e As System.EventArgs)
   'Every time a picturebox is clicked, this variable will contain THAT picturebox
   Dim picBox As PictureBox = DirectCast(sender, PictureBox)

   'Do something with the picBox control
End Sub

Perfect! Exactly what I needed! :) Thanks

Hi, I have the same issue here but I need to know what picture box was pressed... how do I gather the array's index? thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.