TCanvas.TextRect parameters lazarus / 21-General ---------------------------------------------------------------------- PunyDog · 2023-04-19 07:26 So TCanvas parameters described as this procedure TCanvas.TextRect(   ARect: TRect;   X: Integer;   Y: Integer;   const Text: string;   const Style: TTextStyle ); virtual; I know it's basic, but I'm in low energy right now and the online manual does not clearly state it. Perhaps I shall go to sleep a few hours and try it myself afterwards.  1. Does ARect represent the actual position on Canvas (left, top, right, bottom) or the start position and size (left, top, width, height)? 2. What about X and Y? Are they the actual position on Canvas or the relative position from the left-top of the Canvas? ---------------------------------------------------------------------- wp · 2023-04-19 08:14 Yes, this is far from logical, and the guy at Borland who invented this must have smoked a lot that day... Run the attached demo and see yourself. The position of the text is determined by four parameters: - the rectangle parameter - X - Y - TextStyle.Alignment - TextStyle.Layout When TextStyle.Aligment is alLeftJustify the Rect.Left is ignored, and the text position is given by X which must be relative to the canvas rather than to the rectangle. Likewise, when TextStyle.Layout is tlTop the Rect.Top is ignored, and the text position is given by Y which must be relative the the canvas rather than to the rectangle. But in the other TextStyle.Alignment (TextStyle.Layout) cases, X (Y) is ignored, and the text is centered or right(bottom)-aligned within the rectangle. A more logical meaning of the parameters would have been (in my opinion) to control the text position by the rectangle and the alignment/layout values and to use X and Y as offsets so that the text can be shifted relative to its default position. Anyway, there is another text drawing command, the windows-like DrawText which - if used from the LCLIntf unit - is cross-platform. It does not have the confusing X and Y parameters and controls the position only by the rectangle and the options packed into the last "Flags" parameter. Note, however, that the option DT_SINGLELINE must be included, too. Example for bottom/right aligned text: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  LCLIntf, LCLType;...  s := 'bottom/right';  DrawText(Paintbox1.Canvas.Handle, PChar(s), Length(s), DT_RIGHT or DT_BOTTOM or DT_SINGLELINE); The attached demo contains the Canvas.TextRect and the DrawText methods in the left and right paintboxes, respectively. Added some further text to the wiki article: https://wiki.freepascal.org/Graphics_- _Working_with_TCanvas#Drawing_Text ---------------------------------------------------------------------- AlexTP · 2023-04-19 09:17 @wp, Thanks for info. Would be good to have this info at https://wiki.freepascal.org/TCanvas#Drawing_Text ---------------------------------------------------------------------- wp · 2023-04-19 09:22 That's where I put it shortly before you submitted your message.