0

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

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by Luigiview
0
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
0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.