title: How to respond to events for objects in an array
body: <p>I have made an array of tiles (pictureboxes) in an array and need them to all do something when clicked, but don't know how. Specifically, I want to be able to place some other object on them by clicking a tile and making that object go to that tile's location. I know you may suggest looking at the mouseposition variable and having some invisible box over all the tiles to register clicks, but I would like to know how to register any event for an object in an array for anything that comes up in the future. I do know how to register events for objects which aren't in an array by the way.
  The object I want to move on top of the picturebox will also be from an object array, but a different one.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Public Class Form1
      Dim tiles(50) As PictureBox 'This is the object array of tiles
      Dim plants() As String 'I haven't set this up yet, but this will be for the objects to be 'placed' on the pictureboxes.
  
      Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
          Dim tileWidth As Integer = 50
          Dim tileHeight As Integer = 50
          Dim xindent As Integer = 10
          Dim yindent As Integer = 10
          For x = 0 To 9
              For y = 0 To 4
                  ReDim Preserve tiles(x * y)
                  tiles(x * y) = New PictureBox With {.Visible = True, .Size = New System.Drawing.Size(50, 50), .Parent = Me, .BackColor = Color.GreenYellow, .Image = Nothing}
                  tiles(x * y).Location = New System.Drawing.Point(x * tileWidth + xindent, y * tileHeight + yindent)
                  If (x Mod 2 = 0 And y Mod 2 = 0) Or (x Mod 2 &lt;&gt; 0 And y Mod 2 &lt;&gt; 0) Then
                      tiles(x * y).BackColor = Color.Green
                  End If
              Next
          Next
      End Sub
  End Class
  </code></pre>
  
  <p>I simply don't know how to set up the click event handler for the array of tiles so that's why its not in the code above.</p>
  
  <p>Thanks in advance for your help.</p>