Picture Box Array Problem
-
I want to create an array of picture boxes (about 10) through code. I have done this succesfully and have them showing up on the form just fine. I can control the size/color and all of that fine when I create them, but after they are on the screen, I can not click on them and get it to run code. I have used the addhandler to assign a click, but when it runs, I don' know how to tell it which box I clicked on. I want to be able to have the pic box I click on change it's image to a different one. When I do this, it always changes the last box, not the one I click on. I found the arrays don't work as they did in VB 6. Please help :sigh:
-
I want to create an array of picture boxes (about 10) through code. I have done this succesfully and have them showing up on the form just fine. I can control the size/color and all of that fine when I create them, but after they are on the screen, I can not click on them and get it to run code. I have used the addhandler to assign a click, but when it runs, I don' know how to tell it which box I clicked on. I want to be able to have the pic box I click on change it's image to a different one. When I do this, it always changes the last box, not the one I click on. I found the arrays don't work as they did in VB 6. Please help :sigh:
Well the event handler of PictureBox click has an object parameter called Sender, which is actually the picturebox object clicked. To do what you want, this is what you do:
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Dim a As PictureBox = CType(sender, PictureBox)
a.Image = .....HTH
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler. Support Bone