Copy section of Picturebox to another Picturebox

NinthWaver

New member
Joined
Dec 30, 2012
Messages
3
Programming Experience
5-10
I have drawn graphics to a Picturebox in Paint() using e.Graphics and I am looking to copy a section of this to another Picturebox.

I have found many pages telling me how I can copy a section of a Picturebox Image, however this does not seem to include what is painted with e.Graphics.


Is there any way to copy a section of what I have painted with e.Graphics onto another Picturebox?
 
If you're drawing on a PictureBox then there's nothing to copy. Your options are to either do the same drawing on the other PictureBox or to do the same drawing on an Image and then draw that onto the other PictureBox. As it is only a portion of the original drawing you want, I'd probably suggest the second option.

Create a new Bitmap object of the appropriate dimensions, call Graphics.FromImage and then use the same GDI+ calls to do the same drawing. You can then call DrawImage in the Paint event handler of the second PictureBox to draw that Bitmap onto it.
 
Other methods that can be used is PictureBox.DrawToBitmap or Graphics.CopyFromScreen, see for example Screenshot Area (Picturebox)

I'd probably avoid the latter, given that it wouldn't account for some other window possibly covering that part of your form.
 
Back
Top