Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating PictureBox Array Event Handler at Runtime

Status
Not open for further replies.

Agent00Kevin

Programmer
Dec 26, 2008
5
I'm programming a simple game that uses an 8 by 8 game board (just like a chess board). Each square is part of a PictureBox array that is created at runtime. I used the following code:

Dim picSquareImage(8, 8) As PictureBox

I could never figure out how to create a PictureBox array at Designtime. If this is possible, please let me know as that would be the easiest way to solve my problems.

Anyhow, I successfully created, loaded, and placed the images on my form. However, the game requires that I program what happens when you click on or hover the mouse over the individual PictureBoxes. I cannot figure out though how to program the events. I tried the following code:

Private Sub picSquareImage(1, 1)_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picSquareImage(1, 1).Click

DetermineIfMoveIsAllowed(picSquareImage(1, 1), 1, 1)
If MoveIsAllowed Then
MakeMove(picSquareImage(1, 1), 1, 1)
End If

End Sub

This code, of course, is designed to handle the event of the user clicking on the square (PictureBox) in row 1, column 1.

The problem is that VB doesn't recognize picSquareImage(1, 1) or any of the 64 PictureBoxes in the array because they are not created until Runtime.

My question is how do I create the code at Runtime to handle various events or how do I create a multidimensional PictureBox array at design time? Any help would be greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top