I have drawn something on my form
But after minimizing and restoring the form, the form gets cleared up. What could the problem be?
And this Codes is wrong :(JIT Says:)
private void Form1_Paint(object sender, PaintEventArgs e)
{
grForm = e.Graphics;
}
Because the clipping bound of grForm are less than zero or too big .
You cannot store the e.Graphics object you get in the Paint event. It is only valid while the Paint event runs, it gets disposed right after that. Using the form’s CreateGraphics() method doesn’t work either, that gets wiped out as soon as the form needs to be repainted. When you minimize and restore it for example.
You must use the form’s Invalidate() method to force the Paint event to run again. Then draw whatever needs to be drawn. If you want the drawing to be persistent then you have to draw in a Bitmap. Use e.Graphics.DrawImage() in the Paint event to draw the bitmap. This is not the best way, just redrawing whenever necessary is best.