repainting own panel-component

From: Dirk Hennings (dhennings_at_gmx.de)
Date: 03/27/04


Date: Sat, 27 Mar 2004 11:44:24 +0100

Hi,

I'm building a component derived from TPanel that should have a
stripe-pattern (horizontal stripes with two colors changing after every 3
pixel)
Everything works fine, but I guess my application slows down a lot.
Resizing my form leads to a resize of my component.
I redraw the the component if the bounds change or paint is called:

procedure TStripePanel.SetBounds(...)
begin
inherited setbounds(...)
updatebackground
invalidate;
end;

procedure TStripePanel.Paint;
begin
inherited
canvas.copyrect(..., background.bitmap.canvas, ...); copies the
background-picture on the canvas

Creating my component I create a starting background-picture with drawline.
If the bounds change I don't always create it again, but if it grows I copy
parts of the picture with stretchdraw to the newly parts of my component.
I do this on the backgroundpicture, so that the canvas is not directly drawn
to.
Only if paint is called I copy the picture from the background-picture to
the canvas.

I am not sure if this is the best solution to do this.
I don't know if the "pre"-painting in the background-picture consumes most
of the time.
I also heard that some components only redraw the section of themselves that
has changed.
Is there any way to do this and _should_ someone do this when creating his
own component?

The repainting-"theories" of component-writing is kind of new for me. I
managed to get the component working and was happy at first. But since I
wrote a lot of them lately I began to wonder if I could consume a little too
much CPU-time than necessary.

All help is highly appriciated.
Thanks by now

Dirk