TPaintBox losing content momentarily.

I'm writing a program (Delphi 5) which generates several smallish preview images (stored in TBitmaps), which I show in a TPaintBox. These are overwritten during successive generations of images, allowing the last generation to be seen as the new ones overwrite them. Sometimes (usually on the very first run of the program), the TPaintbox gets cleared to white halfway through the generation. The paintbox keeps drawing the next half of images, and only re-displays the first half when the onpaint event occurs. BTW, I have a flag in the onpaint handler to prevent drawing of images until they are ready to be drawn, and to only draw the TBitmaps which contain data. And each image is displayed just after it is filled with data, so I can see it being drawn line by line.

  Because the images are already stored as smallish TBitmaps, I don't want to use double-buffering with a paintbox-size offscreen bitmap.
So, why is the TPainbox clearing?
BTW, it isn't occuring at the same place every time, and I've set the controlstyle to csOpaque.
davedave4Asked:
Who is Participating?
 
scrapdogConnect With a Mentor Commented:
I couldn't tell you the "proper" way, but if it works, it works!
0
 
scrapdogCommented:
>So, why is the TPainbox clearing?

In the OnPaint, the canvas is cleared.  Therefore, the only images that will be shown are the ones you draw there...the ones that were previously there will be gone.

You will have to redraw the images that were already there, in addition to the ones that are ready to be drawn.
0
 
davedave4Author Commented:
Yeah, I was redrawing the images in the onpaint event. However, the problem was that my program was setting the size of the painbox every time it ran through the loop. I had it this way so if the form was resized, the preview images would be redrawn to fill the whole width of the form, no matter what it was resized to. What I didn't realise is that a TPaintbox isn't actually resized until the next WM_PAINT message (or so it seems - am I correct here?) I fixed the problem by calling the Update method straight after resizing. Is this the proper way of going about it? It seems to work, anyway.
Dave.
0
 
scrapdogCommented:
Thanks for the points!

I don't know if I really deserved them???   but I'm glad you got your program working...
0
All Courses

From novice to tech pro — start learning today.