1

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();





    }


  • Is it asp.net or winforms? - Fredrik Mörk
  • if you clean up the code sample, comment where the variables come from and what the functions called do, and clarify whether you are adding PictureBoxes one-at-at-time, or just moving PictureBoxes left-to-right in a pre-defined set of PictureBoxes on a Form, I think you'll get more useful answers. - BillW

3 답변


2

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();
}


  • Hey Its useful for Me ... I got the Output ... Thanx Yar.. - Suryakavitha

0

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


  • thanks LakhlaniPrashant... but i Wrote that line on my code... the problem is which picture box got clicked.... inthat Click event i have to pass that particular image to Next form's picturebox... how do i!!! - Suryakavitha

0

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!


  • Hey I got The Correct output....Its Very useful For Me... Thanks Yar... - Suryakavitha

Related

Latest