[SOLVED]TStringGrid.DrawCell Alignment not working with TextOut lazarus / 31-LCL ---------------------------------------------------------------------- goldenfox · 2012-04-15 09:51 Hi guys! I'm currently exploring lazarus and stumbled upon this code which I can't resolve and would like to ask for your guidance. I can't figure out how to right align text in a column inside TStringGrid.DrawCell proc. Maybe I just missed something. Here's a snippet Quoteprocedure TfrmChart.sgChartDrawCell(Sender : TObject; aCol, aRow : Integer;   aRect : TRect; aState : TGridDrawState); var    fBalance : extended = 0;    rAlign: TTextStyle; begin   if aRow > 0 then   begin     if (aCol = 1) and (sgChart.Cells[2,aRow] = 'GL')  then       with sgChart do       begin         Canvas.Font.Style := [fsBold];         Canvas.FillRect(aRect);         Canvas.TextOut(aRect.Left + 2, aRect.Top + 2, Cells[aCol,aRow]);       end;     if (aCol = 3) then       with sgChart do       begin         rAlign := Canvas.TextStyle;         rAlign.Alignment := taRightJustify;         Canvas.TextStyle := rAlign;         Canvas.FillRect(aRect);         fBalance := StrToFloat(Cells[aCol,aRow]);         if fBalance < 0 then Canvas.Font.Color := clRed;         Canvas.TextOut(aRect.Left + 2, aRect.Top + 2, FormatFloat('#,##0.00;(#,##0.00)',fBalance));       end;   end; end; Additional: Windows 7 Ultimate 32bit lazarus 1.1 SVN 36782 Thank's a lot =) ---------------------------------------------------------------------- theo · 2012-04-15 10:39 You can do a lot more using Canvas.TextRect http://lazarus- ccr.sourceforge.net/docs/lcl/graphics/tcanvas.textrect.html with TTextStyle http://lazarus-ccr.sourceforge.net/docs/lcl/graphics/ttextstyle.html ---------------------------------------------------------------------- goldenfox · 2012-04-15 10:49 Quote from: theo on April 15, 2012, 12:39:41 pmYou can do a lot more using Canvas.TextRect http://lazarus- ccr.sourceforge.net/docs/lcl/graphics/tcanvas.textrect.html with TTextStyle http://lazarus-ccr.sourceforge.net/docs/lcl/graphics/ttextstyle.html Thanks for the hint theo. It's working with TextRect. But I'm wondering why it's not working with TextOut Here's what I changed to make it work QuoteCanvas.TextRect(aRect,aRect.Left - 2, aRect.Top + 2, FormatFloat('#,##0.00;(#,##0.00)',fBalance),rAlign); ---------------------------------------------------------------------- KpjComp · 2012-04-16 20:33 Quote from: goldenfox on April 15, 2012, 12:49:28 pmBut I'm wondering why it's not working with TextOut Code: [Select]TTextStyle = packed record     Alignment : TAlignment;  // TextRect Only: horizontal alignment  http://lazarus-ccr.sourceforge.net/docs/lcl/graphics/ttextstyle.html QuoteAlignment : TextRect Only: horizontal alignment