Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-09

Paintbox complete redraw

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Benito van der Zander
Show quoted text 6 lines
If you replace rgb(random(255),random(255),random(255)) with rgb(100, 100, 100) you'll not notice the repainting because it will be painted in the same indistinguishable colour as before

Yes, of course, but I need to draw something like a mini screenshot which is different nearly every time it is drawn and depends on the position of
every window.

So how can you redraw the paintbox complete in OnPaint?

Benito

Reply by email

Howard Page-Clark
to Benito van der Zander
Benito van der Zander wrote
So how can you redraw the paintbox complete in OnPaint?

This is a hack, so I hope another may show you how to do it properly.

Add a boolean flag to your form class thus:

type
  TForm1 = class( TForm )
    ...
    private
    FOnPaintCalled: boolean;
    ...
end;

and a Formcreate event handler to initialise FOnPaintCalled:

PROCEDURE Tform1 .Formcreate ( Sender : Tobject ) ;
BEGIN
  inherited;
  FOnPaintCalled := false;
End;

and write the OnPaint handler as follows:

PROCEDURE Tform1 .Paintbox1paint ( Sender : Tobject ) ;
BEGIN
  PaintBox1.Canvas.brush.Color:=rgb( random(255), random(255), random(255) );
  PaintBox1.Canvas.Rectangle(0, 0, 100, 100);
  if not FOnPaintCalled then Paintbox1.Invalidate;
  FOnPaintCalled := not FOnPaintCalled;
End;

Regards

Howard

Reply by email