Board index » delphi » Simple TRect question

Simple TRect question

How do I create a TRect on-the-fly ??

E.g. I want to assign  (5,10), (100,20) to a canvas, how do I assign
it without making a TRect and set each point seperately before
assigning it?

i.e.   TImage.Canvas.FillRect (  ??????   ) ;

2nd, how do I use ClientRect by shrinking it 2 pixels at each side??

TImage.Canvas.FillRec(TImage.ClientRect);
will fill the whole area.

Now I do as

  Var RR:TRect;

  RR := TImage.ClientRect;
  RR.Top := RR.Top +2;
    RR.Left := RR.Left+ 2;
    RR.Right := RR.Right -2 ;
    RR.Bottom := RR.Bottom -2;
    Image3.Canvas.FillRect(RR);

Which looks very stupid (though works)

Thanks for your help.

 

Re:Simple TRect question


Anders LEE a crit dans le message <355c87e5.10354...@news.hk.super.net>...

Quote

>How do I create a TRect on-the-fly ??

>E.g. I want to assign  (5,10), (100,20) to a canvas, how do I assign
>it without making a TRect and set each point seperately before
>assigning it?

>i.e.   TImage.Canvas.FillRect (  ??????   ) ;

Use the Rect function

Quote

>2nd, how do I use ClientRect by shrinking it 2 pixels at each side??

>TImage.Canvas.FillRec(TImage.ClientRect);
>will fill the whole area.

>Now I do as

>  Var RR:TRect;

>  RR := TImage.ClientRect;
>  RR.Top := RR.Top +2;
>    RR.Left := RR.Left+ 2;
>    RR.Right := RR.Right -2 ;
>    RR.Bottom := RR.Bottom -2;
>    Image3.Canvas.FillRect(RR);

>Which looks very stupid (though works)

Use the InflateRect function

- Show quoted text -

Quote

>Thanks for your help.

Re:Simple TRect question


In article <355c87e5.10354...@news.hk.super.net>, and...@aelhk.com (Anders LEE)
writes:

Quote
>How do I create a TRect on-the-fly ??

>E.g. I want to assign  (5,10), (100,20) to a canvas, how do I assign
>it without making a TRect and set each point seperately before
>assigning it?

>i.e.   TImage.Canvas.FillRect (  ??????   ) ;

        Image.Canvas.FillRect(Rect(5, 10, 100, 20));

Quote

>2nd, how do I use ClientRect by shrinking it 2 pixels at each side??

>TImage.Canvas.FillRec(TImage.ClientRect);
>will fill the whole area.

>Now I do as

>  Var RR:TRect;

>  RR := TImage.ClientRect;
>  RR.Top := RR.Top +2;
>    RR.Left := RR.Left+ 2;
>    RR.Right := RR.Right -2 ;
>    RR.Bottom := RR.Bottom -2;
>    Image3.Canvas.FillRect(RR);

>Which looks very stupid (though works)

with Image do
  Image3.Canvas.FillRect(Rect(2, 2, ClientWidth - 2, ClientWidth - 2));

Rect(ALeft, ATop, ARight, ABottom) returns a TRect with the bounds given.

BTW keep "T" prefixed names for types, don't use them for objects or variables
- it's the Delphi convention.

Alan Lloyd
alangll...@aol.com

Re:Simple TRect question


In article <6ji8tn$29...@news4.isdnet.net>, "Christian Poisson"

Quote
<christian.pois...@hol.fr> writes:
>Use the InflateRect function

Good suggestion, but wouldn't you also need to use the OffsetRect function ie
:-

    FillRect(OffsetRect(InflateRect(ClipRect, -4,-4), 2, 2)));

Alan Lloyd
alangll...@aol.com

Other Threads