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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

>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.
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.
I couldn't tell you the "proper" way, but if it works, it works!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thanks for the points!

I don't know if I really deserved them???   but I'm glad you got your program working...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.