If you draw directly on the PictureBox
, the drawn polygons will be lost when the control is repainted (e.g. when you resize the window). A better way is to draw on a Bitmap
and add then show it in the PictureBox
. An example:
// A new bitmap with the same size as the PictureBox
var bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
//Get the graphics objectm which we can use to draw
var graphics = Graphics.FromImage(bitmap);
//Draw stuff
graphics.FillRectangle(Brushes.Red, new Rectangle(0, 0, 500, 500));
//Show the bitmap with graphics image in the PictureBox
pictureBox1.Image = bitmap;