RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCanvas.TextRect Method (TRect, Integer, Integer, string)

Writes a string inside a clipping rectangle.

Pascal
procedure TextRect(var Rect: TRect; var Text: string; TextFormat: TTextFormat = []); overload;
procedure TextRect(Rect: TRect; X: Integer; Y: Integer; const Text: string); overload;
C++
__fastcall TextRect(TRect Rect, AnsiString Text, TTextFormat TextFormat = []);
__fastcall TextRect(TRect Rect, int X, int Y, const AnsiString Text);

Use TextRect to write a string within a limited rectangular region. Any portions of the string that fall outside the rectangle passed in the Rect parameter are clipped and don't appear. The upper left corner of the text is placed at the point (X, Y).  

C++ Examples: 

 

/*
The following code displays the text "Hello, world!" in a
rectangle defined by the coordinates (10, 10) and (100, 100).
After displaying the text with the TextRect method, the code
draws a black, vertical line frame around the rectangle.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TRect TheRect = Rect(10,10,100,100);
  Canvas->TextRect(TheRect, 10, 10, "Hello World");
  Canvas->Brush->Color = clBlack;
  Canvas->FrameRect(TheRect);
}

 

Delphi Examples: 

{
The following code displays the text "Hello, world!" in a 
rectangle defined by the coordinates (10, 10) and (100, 100).
After displaying the text with the TextRect method, the code
draws a black, vertical line frame around the rectangle.
} 
procedure TForm1.Button1Click(Sender: TObject);
var TheRect: TRect;
begin
  TheRect := Rect(10,10,100,100);
  Form1.Canvas.TextRect(TheRect,10,10,'Hello, world!');
  Form1.Canvas.Brush.Color := clBlack;
  Form1.Canvas.FrameRect(TheRect);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!