Link to home
Avatar of futuremoose
futuremoose

asked on

Graphics on form not being saved to file

Hello,

I have a very simple vb.net example, where I am using GDI+ to draw a simple pattern directly on the form... just a checkerboard of black/white squares. That bit works fine. See the attached screenshot.

However, if I try to save the form as an image file, the pattern I drew is not included (again, see screenshot). The pattern does not get erased off the form, but it is not included in the image file.

If the form is "refreshed", or another window covers up the pattern, then it is erased... that part I understand. But I don't know why the pattern does not show up on the image saved to a file.

I have included the Form1.vb file, which has all the code... to try it just create a new form with 3 buttons, and copy/paste the contents of my Form1.vb into yours.
sshot.jpg
Form1.vb
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of futuremoose
futuremoose

ASKER

Yes, your code works fine.

Actually, I had already found a workaround... by creating a Bitmap (bmp), getting the Graphics using Graphics.FromImage(bmp), drawing what I needed, and then using PictureBox.Image = bmp to display the result works fine. Plus them I can just do a bmp.Save.

But your answer uses the Form1_Paint event, which I should investigate as a possibly more proper approach. Thanks.