Fog Creek Software
Discussion Board

I have a little probelm...

When I draw some graphics on a form in canvas it dissapears after minimizing application...
How do i fix it?

Thnx ;-)

Tuesday, October 22, 2002

Only draw inside OnPaint events.

Frederik Slijkerman
Tuesday, October 22, 2002

To manually trigger a redraw, call Invalidate or Refresh on a control or on the form.

Frederik Slijkerman
Tuesday, October 22, 2002

If you don't want to have to explicitly draw everything again when the canvas needs refreshed, a common method is to use a buffer. I'm going to assume you're using the main form's canvas, but this applies just as well to a paintbox or any other on-screen canvas. Create a TBitmap the same size as the form's canvas, do all your drawing on the bitmap's canvas. In the OnPaint for the form's canvas just copy the bitmap's canvas to the form's canvas. Every time you draw to the bitmap's canvas you'll need to force the form to update or write an extra procedure that only updates changed areas.
If you're doing a lot of drawing this will be orders of magnitude faster than drawing directly to an on-screen canvas and you won't have the problem you've described.

Ryan Eibling
Tuesday, October 22, 2002

One way to reduce the clutter of creating all these Bitmap objects by hand and making sure they're painted and stuff is by simply using a TImage. It's a visual component to display bitmaps. You don't really *have* to load a bitmap from a file, you can also start from an empty one and draw on its canvas.


Dave Van den Eynde
Wednesday, October 30, 2002

*  Recent Topics

*  Fog Creek Home