Board index » delphi » PaintBox InvalidateRect
Shawn Jones
![]() Delphi Developer |
PaintBox InvalidateRect2006-08-29 12:21:06 AM delphi119 I'm trying to optimize a paintBox's Paint procedure. It draws a series of moveto lineto's (a stock market bar chart). I want the app to be able to Invalidate just part of the paintBox then have the Paint procedure just draw those affected lines. This would be the style defined by Petzold in Progamming Windows (win32). It looks like I can use pb1.Canvas.ClipRect on the Paint side, which is good, but I can not figure out a way to just invalidate part of the paintBox. It looks like its all (Invalidate) or nothing. According to the docs it says use the win32 function SelectClipRgn. So to verify that I am invalidating a specific region and the Paint 'sees' this region I have tried the following code which does not work (doing this directly on a Form does work using the win32 InvalidateRect). Should I even be using a TPaintBox for this? unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) pb1: TPaintBox; Button1: TButton; procedure Button1Click(Sender: TObject); procedure pb1Paint(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var rec: TRect; region: hRGN; begin //rec := Rect(50,50,100,100); //InvalidateRect(pb1.Canvas.Handle, @rec, true); //This doesn't seem to work. region := CreateRectRgn(50,50,100,100); SelectClipRgn(pb1.Canvas.Handle, region); //This doesn't seem to work either. pb1.Update; end; procedure TForm1.pb1Paint(Sender: TObject); begin pb1.Canvas.Rectangle(pb1.Canvas.ClipRect); //Identify ClipRect location end; end. |