Event Handlers in Arrays

  • Thread starter Thread starter Xarky
  • Start date Start date
X

Xarky

Hi,
I am creating an array of PictureBoxes on my Windows Form.

PictureBox temp;
PictureBox[10,10] myArea = new Picture
for (int x=0; x<10; x++)
{
for (int y=0; y<10; y++)
{
temp = new PictureBox();
temp.Location = new Point(1+(x*MAX), 1+(y*MAX));
temp.Size = new Size(MAX, MAX);
temp.BackColor = System.Drawing.Color.Green;

myArea[x, y] = temp;
myArea[x, y].Click +=new EventHandler(my_Click);
this.Controls.Add(temp);
}
}


private void my_Click(object sender, EventArgs e)
{
// now here I need to get the PictureBox which was clicked and do
some operations on it.

}


Can someone tell me how to get which picturebox was clicked?

Thanks in Advance for your help
 
if the eventhandler is invoked, the picturebox that was clicked is passed as
the "sender"-parameter, you just cast it back to PictureBox if necessary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top