Board index » delphi » How to set ClipRect on TCanvas?

How to set ClipRect on TCanvas?

Is there any way to set the clipping area (ClipRect property)
for the TCanvas?

I'm writing a framework for a drawing tool, which I need for
myself.  I really need to set the clipping area to reduce overhead
drawing all the items.  But found that TCanvas.ClipRect is
read-only!

Thanks, in advance, for your quick reply!

Hernan

 

Re:How to set ClipRect on TCanvas?


Quote
Hernando TANAKA wrote:

> Is there any way to set the clipping area (ClipRect property)
> for the TCanvas?

> I'm writing a framework for a drawing tool, which I need for
> myself.  I really need to set the clipping area to reduce overhead
> drawing all the items.  But found that TCanvas.ClipRect is
> read-only!

> Thanks, in advance, for your quick reply!

> Hernan

I have done some stuff with the ClipRect routines (API) for a
printer canvas. But I want a simple rectangle moved across the
paper by defined margin amounts. If you want to temporarily
refresh just part of your drawing, maybe this is one method :

If you want the area (100,100) to (200,200) defined as the clip-
rect you could try :

  ExcludeClipRect(Canvas.Handle, 0,0,Canvas.Width,100);
  ExcludeClipRect(Canvas.Handle, 0,200,Canvas.Width,Canvas.Height);

  ExcludeClipRect(Canvas.Handle, 0,100,100,200);
  ExcludeClipRect(Canvas.Handle, 200,100,Canvas.Width,200);

Check the help on this API call, there are others.

HTH

Ray Cramer
R...@Pol.ac.uk

Re:How to set ClipRect on TCanvas?


I got some e-mails how to set the clipping area.
The simplest one was like this;

  ClipRgn: HRGN;

  ClipRgn := CreateRectRgn(Left, Top, Right, Bottom);
  SelectClipRgn(Canvas.Handle, ClipRgn);

and this works fine even for offscreen canvas like TBitmap canvas.
I still don't know why Borland didn't make TCanvas.ClipRect
writable.

Thanks for everyone who kindly answered my question.

Regards,

Re:How to set ClipRect on TCanvas?


Hi,

I am sure the original post contained as well the third line

DeleteObject(ClipRgn)

after selecting cliprgn. Otherwise a nice resource leakage :-)

cu
olli

___________________________________________________________
__to use my e-mail address, please remove all underscores__
___________________________________________________________

Other Threads