i have generated picturebox dynamically... now i have to displaying Different images on that picture boxes after that when i click the particular picture box it should be displayed in the next form Picture box.... how do i know the particular picturebox got clicked.... and How can I do it... reply me.. Thanks In Advance..
and my coding is
for(int i=0;i
shapes[i].Location = new Point(Left,Top);
Left += 200;
Top += i + 0;
shapes[i].Size = new Size(150, 150);
shapes[i].BackColor = Color.Black;
shapes[i].Visible = true;
shapes[i].BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(shapes[i]);
shapes[i].Click += new EventHandler(PictureBox_Click);
}
private void PictureBox_Click(object sender, EventArgs e) {
int imageid = 1;
ClsProperty.ImageId = imageid;
fd2 = new frmImageDisplay(imageid, ClsProperty.ipaddress);
fd2.Show();
}
The "sender" in the event handler will be the picture box that got clicked:
private void PictureBox_Click(object sender, EventArgs e) {
PictureBox senderAsPictureBox = sender as PictureBox;
//this is the picture box that got clicked
int imageid = 1;
ClsProperty.ImageId = imageid;
fd2 = new frmImageDisplay(imageid, ClsProperty.ipaddress);
fd2.Show();
}
It would be helpful if you show your code, but anyways, if you are dynamically creating a picture box, you can add a code like .Click += your method name. This is more help about dynamically adding an event to the control when adding them
Hope it helps
Ok, I think it's easy, the first argument of event is always object sender, cast it to the picture box object and read the ID property, and you can move forward with your problem!