-
February 2nd, 2011, 10:05 AM
#1
2D PictureBox Array
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();
}
}
-
February 2nd, 2011, 10:17 AM
#2
Re: 2D PictureBox Array
I got it working another way. I inserted
pictureBox[i, j].Name = i.ToString() + j.ToString();
then displayed it
MessageBox.Show(pictureBox[i, j].Name);
Is there another way of finding out the index value?
-
February 2nd, 2011, 10:36 AM
#3
Re: 2D PictureBox Array
Another quick question....
How can I get the i and j values and pass them to my ctrlClick method?
-
February 2nd, 2011, 11:00 AM
#4
Re: 2D PictureBox Array
Got it.
MessageBox.Show(ctrl.Name);
thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|