title: C# - Click event sending a value
body: <p>I'm using a for-loop to add values into an array of PictureBox and binding a click event to each one. I'm looking for a way of getting the data of a PictureBox after clicking on it. Since it's an array, I was thinking of sending the value of the loop counter, which would identify which one was clicked.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>PictureBox[] picboxes = new PictureBox[result];
  for (int i = 0; i &lt; results; i++)
  {
      picboxes[i] = new PictureBox();
      picboxes[i].ImageLocation = @FormIni.RetRes((i * 5) + 5 + i);
      picboxes[i].Click += new System.EventHandler(PictureBoxes_Click);
  }
  
  private void PictureBoxes_Click(object sender, EventArgs e)
  {
      label1.Text = "here I need the value of the picboxes[i] image location";
  }
  </code></pre>
  
  <p>It can seem stupid, but I thought of something like:</p>
  
  <p><code>picboxes[i].Click += new System.EventHandler(PictureBoxes_Click(i))</code></p>
  
  <p>and</p>
  
  <p><code>private void PictureBoxes_Click(object sender, EventArgs e, int i)</code></p>
  
  <p>In short: when I click in a PictureBox created in a array via code, how do I get its values (inside the click event handler)?</p>
  
  <p><strong>EDIT!</strong></p>
  
  <p>Sorry for finding it only after making this question, but I've found <a href="https://stackoverflow.com/questions/15748429/get-the-index-of-array-of-picturebox-clicked">this</a> solution and it may apply to my case, right?</p>