Question: Creating a control array with picture boxes

Joined
Jun 29, 2006
Messages
6
Location
Seaford, LINY---Las Vegas, NV
Programming Experience
1-3
I'm trying to create a control array using picture boxes. basically in the end i want to be able to click the picturebox which is in an array and have it call an event. it needs to pass the index value of the picturebox clicked for the program to work

so far i've added an event handler but im not doing something right:

AddHandler PictureBox1.click, AddressOf PictureBox1_Click

it doesn't even call the sub routine. it tells me that .click is not an event of a one dimensional array

any advice.
 
i guess a little more of the code would perhaps better help explain.


''In my general declarations
Dim pbBody() As PictureBox
Dim bmBody() As Bitmap



'Where I Fill The Array
Public Function getBody() As String
Dim i As Long

Try
'Function that calculates the number of records
'so I know how many Picture boxes to make
GetRecordCount()

Dim dbConn As OleDbConnection
Dim dbCommand As New OleDbCommand()
Dim strPath As String
strPath = "c:\CharBody.mdb"

'Load the Body Skins
dbConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & strPath)
dbCommand.CommandText =
"SELECT ID FROM " & AccessFolder
dbCommand.Connection = dbConn
dbConn.Open()

Dim dbDR As OleDb.OleDbDataReader _
= dbCommand.ExecuteReader

'Resize the picturebox array to accomodate the number
'of pictures in the database
ReDim pbBody(rowCount)
ReDim bmBody(rowCount)

While dbDR.Read
bmBody(i) = Bitmap.FromFile(​
"c:\CharParts\" & _ AccessFolder & "\" & (i + 1) & ".bmp")

pbBody(i) =
New PictureBox
pbBody(i).Image = bmBody(i)
pbBody(i).AutoSize =
True
pbBody(i).Visible = True
flpBody.Controls.Add(pbBody(i))

'Now this is where I've tried all sorts of code
'I want to be able to have it so that if I
'click on a picture it will know which one I clicked
'on perhaps via the index value so I can reference
'that to call back to the database.
addhandler
pbBody.click, addressof pbbody_Click(ByVal index As Integer)

i += 1
End While

dbConn.Close()
rowCount = 0
Catch err As System.Exception
txtError.Text = err.Message
End Try
End Function
 
pbBody is an array, pbBody(i) is an instance of PictureBox.
VB.NET:
addhandler pbBody(i).click, addressof picturebox_Click

The signature of the click event is
VB.NET:
Sub picturebox_Click(sender as System.Object, e as System.EventArgs)
'sender' is the object that fired the event.
 
Back
Top