Question numerous pictureboxes overlaying

Nathandillon

New member
Joined
Jul 5, 2014
Messages
1
Programming Experience
1-3
Okay so I have built an image generator in VB NET and this may sound stupid but I need to know how to export/save the final image but my problem is that I have one main image as the background in a picturebox element and then numerous pictureboxes overlaying it with the generated content, how do I save all of these as one image? Any help is appreciated

thanks
nathan
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,169
Location
Sydney, Australia
Programming Experience
10+
It's hard to know what's best without some more detail but, most likely, the answer is to not use the numerous secondary PictureBoxes but rather use GDI+ to draw on the primary PictureBox. If you have an Image in a PictureBox then you can draw on the Image if you want it to be permanent or you can draw on the PictureBox for it to be temporary, i.e. once you make changes to the Image you can't go back but changes to the PictureBox then you can roll them back or change them if you want. Here's an example of mine that draws on a PictureBox and then transfers that drawing to the Image in the PictureBox when it's final:

Very Simple Drawing Program

Your app won't work exactly the same way but the principle is the same, i.e. handle the Paint event of the PictureBox to draw on the control and then, when you are happy with what you have, call Graphics.FromImage to draw on the Image. You'll likely be calling DrawImage rather than DrawLine but that's just a detail. You'll obviously have to call Save on the Image to actually save it to a file.

Also, keep in mind that the origin for the Image must coincide with the origin for the PictureBox if you want to be able to use the same locations for the child Images in both cases. If they are do not coincide then you'll need some translation code.
 
Top Bottom