Search code examples
c#graphics2d

How to prevent graphics remove from panel onPaint?


I have a Canvas class who is Panel-inherited class that overrides the onPaint method.

My program looks like this:

enter image description here

It works good and all, but when I minimize \ resize the Canvas,

the "hidden" part of the canvas is deleting. I've noticed that I have to override the onPaint method.

But I don't know what to do to "keep" the draw. any suggestion?


Solution

  • You are describing something that happens when you use CreateGraphics. Don't use CreateGraphics, but use the graphic object from the PaintEventArgs parameter, specifically e.Graphics.