Board index » delphi » TCanvas.ClipRect problems

TCanvas.ClipRect problems

I have a number of graphing routines in a unit to which I pass a TCanvas
as a parameter on which the routines draw the graph.  At present, I get
the size of the TCanvas from the ClipRect, eg nWidth :=
TheCanvas.ClipRect.Right - TheCanvas.ClipRect.Left.  This works fine for
a printer canvas or for a top-level form, but if I overlap part of the
form with another application's window and then reveal it again, the
TCanvas.ClipRect corresponds to the overlapped rectangle rather than all
of the form's canvas.  How can I get the coordinates of the whole
canvas?  Alternatively, how can I get all of the form's canvas
"invalidated" even if only part of it is invalidated by Windows (like
C's InvalidateRect())?

I am sure there is something obvious I am overlooking, but I cannot
figure this out.

Thanks in advance for any help.

Ciaran Costelloe

 

Re:TCanvas.ClipRect problems


Given a Canvas, there is no way to determine how large the device it
represents is.  You must use a device specific method to find this
information

For a form or TControl, use ClientRect instead of ClipRect.  

For the printer you can use Printer.PageWidth and Printer.PageHeight.
You may need to make adjustments for the non-printable areas of the
form using the API call GetDeviceCaps.  Actually, the ClipRect may
work for the printer, but I'm not sure.

On Thu, 18 Feb 1999 15:36:02 +0000, Ciaran Costelloe

Quote
<flo...@indigo.ie> wrote:
>I have a number of graphing routines in a unit to which I pass a TCanvas
>as a parameter on which the routines draw the graph.  At present, I get
>the size of the TCanvas from the ClipRect, eg nWidth :=
>TheCanvas.ClipRect.Right - TheCanvas.ClipRect.Left.  This works fine for
>a printer canvas or for a top-level form, but if I overlap part of the
>form with another application's window and then reveal it again, the
>TCanvas.ClipRect corresponds to the overlapped rectangle rather than all
>of the form's canvas.  How can I get the coordinates of the whole
>canvas?  Alternatively, how can I get all of the form's canvas
>"invalidated" even if only part of it is invalidated by Windows (like
>C's InvalidateRect())?

>I am sure there is something obvious I am overlooking, but I cannot
>figure this out.

>Thanks in advance for any help.

>Ciaran Costelloe

Chris Hill
Chris...@aol.com

Re:TCanvas.ClipRect problems


Hi Chris, thanks for the info.

Since ClientRect is not a property of the TCanvas, I'll figure out a way to
get it from the "owner" if it's a form.  I never thought of going back up to
the owner to get what I needed.

By the way, ClipRect works just fine for a TPrinter!

Thannks again,

Ciaran Costelloe

Quote
Chris Hill wrote:
> Given a Canvas, there is no way to determine how large the device it
> represents is.  You must use a device specific method to find this
> information

> For a form or TControl, use ClientRect instead of ClipRect.

> For the printer you can use Printer.PageWidth and Printer.PageHeight.
> You may need to make adjustments for the non-printable areas of the
> form using the API call GetDeviceCaps.  Actually, the ClipRect may
> work for the printer, but I'm not sure.

> On Thu, 18 Feb 1999 15:36:02 +0000, Ciaran Costelloe
> <flo...@indigo.ie> wrote:

> >I have a number of graphing routines in a unit to which I pass a TCanvas
> >as a parameter on which the routines draw the graph.  At present, I get
> >the size of the TCanvas from the ClipRect, eg nWidth :=
> >TheCanvas.ClipRect.Right - TheCanvas.ClipRect.Left.  This works fine for
> >a printer canvas or for a top-level form, but if I overlap part of the
> >form with another application's window and then reveal it again, the
> >TCanvas.ClipRect corresponds to the overlapped rectangle rather than all
> >of the form's canvas.  How can I get the coordinates of the whole
> >canvas?  Alternatively, how can I get all of the form's canvas
> >"invalidated" even if only part of it is invalidated by Windows (like
> >C's InvalidateRect())?

> >I am sure there is something obvious I am overlooking, but I cannot
> >figure this out.

> >Thanks in advance for any help.

> >Ciaran Costelloe

> Chris Hill
> Chris...@aol.com

Re:TCanvas.ClipRect problems


Thanks again Chris.

I sorted it out by adding an optional procedure to my class which I call in
OnPaint that passes ClientRect  to my routines.  Without calling it, the
class defaults to using TCanvas.ClipRect (which works fine for TPrinter).  I
tried using InvalidateRect in OnPaint, but  this posted another OnPaint into
the message queue, so I got an endless sequence of OnPaint messages!
Anyway, everything is fine now, I would not have solved it without your
help.

Ciaran Costelloe

Quote
Chris Hill wrote in message <36cc50ee.642841...@forums.borland.com>...
>Given a Canvas, there is no way to determine how large the device it
>represents is.  You must use a device specific method to find this
>information

>For a form or TControl, use ClientRect instead of ClipRect.

>For the printer you can use Printer.PageWidth and Printer.PageHeight.
>You may need to make adjustments for the non-printable areas of the
>form using the API call GetDeviceCaps.  Actually, the ClipRect may
>work for the printer, but I'm not sure.

>On Thu, 18 Feb 1999 15:36:02 +0000, Ciaran Costelloe
><flo...@indigo.ie> wrote:

>>I have a number of graphing routines in a unit to which I pass a TCanvas
>>as a parameter on which the routines draw the graph.  At present, I get
>>the size of the TCanvas from the ClipRect, eg nWidth :=
>>TheCanvas.ClipRect.Right - TheCanvas.ClipRect.Left.  This works fine for
>>a printer canvas or for a top-level form, but if I overlap part of the
>>form with another application's window and then reveal it again, the
>>TCanvas.ClipRect corresponds to the overlapped rectangle rather than all
>>of the form's canvas.  How can I get the coordinates of the whole
>>canvas?  Alternatively, how can I get all of the form's canvas
>>"invalidated" even if only part of it is invalidated by Windows (like
>>C's InvalidateRect())?

>>I am sure there is something obvious I am overlooking, but I cannot
>>figure this out.

>>Thanks in advance for any help.

>>Ciaran Costelloe

>Chris Hill
>Chris...@aol.com

Other Threads