简体   繁体   中英

Working of the picturebox

How can I transfer the picturebox image in form 1 to another pictureboxbox of form2 in C#.net ? Same goes with the label. Its working in the same form, but not in different forms. Can anyone help me out with this.

I have made the picture box of form2 as public. if i want to transfer it to the picture box of form2 from form1 (firstpicturebox : name of picturebox in form1),

form2 frm2=new form2();
frm2.picturebox1.image=firstpicturebox.image;

It's not working.

Thanks in advance

It looks like you are creating a new instance of Form2 rather than using the existing one.

Try something like:

// in form1
            PictureBox picBox = (PictureBox)Form2.InstanceOfForm.Controls["pictureBox1"];
        picBox.Image = this.firstpicturebox.Image;
// in form2
public static Form InstanceOfForm;
...
// in Form2_Load()
InstanceOfForm = this;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM