Monday, September 20, 2010

C# Tutorial: Keep Graphics on the Form after Minimize

Here is the code

// Declare a Bitmap object.
Bitmap image;

/////////////// Form1_Load /////////////////////////////
// Create a new Bitmap object(an image). Set the image to the size of pictureBox1.
image = new Bitmap(pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

//////////////// PictureBox1_Paint //////////////////
// Draw the image on the pictureBox1.
e.Graphics.DrawImage(image, 0, 0, image.Width, image.Height);

//////////////// Button "Draw my line" ////////////
// Create a graphic object from the image.
Graphics g = Graphics.FromImage(image);
// Draw a line on the image.
g.DrawLine(Pens.Red, 50, 50, 75, 200);
// Redraw pictureBox1.
pictureBox1.Invalidate();

Or download the solution

No comments:

Post a Comment