Hi,

Im working on an app that displays pictureboxes dynamically through a 2d array. I have it working but I am trying to find the value of a selected picturebox using a click event by displaying it through a messagebox. I cannot figure out how to do this. Please help if you can.

My code below:

public partial class Form1 : Form
{
private PictureBox[,] pictureBox;

private void displayImageBoxArray()
{
pictureBox = new PictureBox[3, 3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
//string test = pictureBox[i.ToString(), j.ToString()];
pictureBox[i, j] = new PictureBox();
pictureBox[i, j].Left = i * 50;
pictureBox[i, j].Top = j * 50;
pictureBox[i, j].Width = 40;
pictureBox[i, j].Height = 40;
pictureBox[i, j].BackColor = Color.Black;
pictureBox[i, j].Click += new EventHandler(ctrlClick);
this.Controls.Add(pictureBox[i, j]);
//MessageBox.Show(pictureBox[i, j.ToString());
}
}
}

private void ctrlClick(System.Object sender, EventArgs e)
{
Control ctrl = (Control)sender;
MessageBox.Show("The index of pictureBox???");
}

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
displayImageBoxArray();
}
}