Control Arrays (pictureboxes)

Jul 12 2009 6:07 AM

I am having difficulty implementing my idea, vb.net just doesn't accept certain methods.
What i want is to create 10 picture boxes at runtime - can do, no probs there.
Creating them in an array seems to be working fine - however when I try to create a Mousemove/mouseclick function to tell me which object in the array i clicked on - Fail, it doesn't accept myarray(whateverindex).name.
Any help would be muchly appreciated. I need it to work this way, because eventually i need around 32 small picture boxes on the form, and a lot of code which obviously i want to operate using the index of each picturebox as the variable, to save me from writing a bunch of code for each picturebox.
Here's the code Ive started with:
Declarations:
Public pcx As Integer = 20 'creates left coordinate for placing picture boxes next to each other instead of overlaid
Public pcarray(10) As PictureBox
 
FORM LOAD:
dim pcindex As Integer = 0
Do
While Val(pcindex) < 11
pcarray(pcindex) =
New PictureBox
pcarray(pcindex).Name =
"PC" & pcindex
pcarray(pcindex).Left = pcx
pcarray(pcindex).Size =
New Size(50, 56)
Controls.Add(pcarray(pcindex))
pcindex = Val(pcindex) + 1
pcx = Val(pcx) + 60
Loop
UP UNTIL HERE, EVERYTHING RUNS FINE - 10 PICTURE BOXES ARE CREATED AT RUNTIME LINED UP NEXT TO EACH OTHER
HERE WHERE I AM STUCK (ACCESSING PROPERTIES OF THE 10 PICTUREBOXES BASED ON THEIR INDEX IN THE ARRAY)
I HAVE UNDERLINED BELOW THE CODE WHICH IS BUNG, HOW CAN I DO THIS CORRECTLY? THE WHOLE PROJECT CODE MAY BE BUNG! LET ME KNOW PLEASE.
 
Private
Sub pc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pcarray(pcindex).click
MessageBox.Show(
"You Clicked on " & pcindex)
End Sub

 
regards
Daniel

Answers (1)