Wednesday, April 6, 2011

How to keep my panel refreshed... it disappears

Hello... In C# (GDI+) when I draw something on the panel using the class Graphics... when I pass another window forground (on the panel) everything I have drawn disapears...!!

How to fix it ?

Thank you...

From stackoverflow
  • You need to paint everything on the Paint event.

    Basically nothing painted is persistent because the windows needs to redraw itself again after it's overlaped, minimized, etc. So, if you want to paint something you need to do it on the Paint event, basically repainting it every time is needed.

    If you only need to paint your stuff after the user clicks on a button, just put your drawing code on the paint event but don't do anything if some flag is not set, your button will only need to set the flag and call the Invalidate method of your panel to force it to redraw itself running your code on the process.

0 comments:

Post a Comment