Connecting Tech Pros Worldwide Help | Site Map

copy image

Newbie
 
Join Date: Nov 2008
Location: UK
Posts: 25
#1: Oct 2 '09
How can i copy a picturebox.image to another picturebox on another form?
thx mark
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,743
#2: Oct 2 '09

re: copy image


The simple line would be
Expand|Select|Wrap|Line Numbers
  1. Form2.PictureBox1.Image =Form1.PictureBox1.Image;
  2.  
But the problem with that is when Form1 goes away and the Image is .Dispose() of, then Form2 has lost it's image as well.

So the best thing to do is clone the image, and give the clone to the second form.
Clone() always returns an object, so you then cast that back into an Image.

Expand|Select|Wrap|Line Numbers
  1. Form2.PictureBox1.Image =(Image)Form1.PictureBox1.Image.Clone();
  2.  
Newbie
 
Join Date: Nov 2008
Location: UK
Posts: 25
#3: Oct 8 '09

re: copy image


Thank you for your help

mrcw
Reply