Then you need to not draw your picture on the pressing of a button but on the painting of the box, then, you toggle within that method wether you do nothing much, or paint the picture in memory.
This will solve all you problems in one hit
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
the problem is you arent drawing to your bitmap you made, you're just drawing on the screen which isnt remembered, a little like the whole if you wave a sparkler in the air you see the picture linger for a little but then its gone.
As I said its the same reason when you minimize and return that the image is gone, because it never really was there..
So, with the way you've done it, you cant. its not real.
You have to change a little about what you did.
Firstly, you need to ensure you have made an image in the first place such as:
Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image = b;
Now your picturebox has an image for you to work with.
Then for example, you can draw on it with such as :
Brush bb = Brushes.White;
Graphics g = Graphics.FromImage(pictureBox1.Image);
g.FillRectangle(bb, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
Pen p = new Pen(Color.Black, 2);
g.DrawLine(p, 0, 0, pictureBox1.Width, pictureBox1.Height);
g.Dispose();
pictureBox1.Invalidate();
pictureBox1.Image.Save("C:\\outpt.bmp");
now open output.bmp and you'll find a white box with a diagonal black line.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190