Align text in StringGrid cells  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 25/11/99

Tip accessed 802 times

 



  • We will make it in the OnDrawCell event, using the API fucntion DrawText.




 procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
   Rect: TRect; State: TGridDrawState);

 var
   Grid    : TStringGrid;
   Texto   : String;

 const
      {Escoger una de las tres}
      {Choose one}
      ALINEACION =
 //                DT_LEFT;
 //                DT_RIGHT;
                 DT_CENTER;

 begin

   Grid := TStringGrid(Sender);

   if (Row < Grid.FixedRows) or (Col < Grid.FixedCols)
   then
     Grid.Canvas.Brush.Color := clBtnFace
   else
     Grid.Canvas.Brush.Color := clWhite;

   Grid.Canvas.FillRect(Rect);
   Texto := Grid.Cells[Col,Row];
   DrawText( Grid.Canvas.Handle,
             PChar(Texto),
             StrLen(PChar(Texto)),
             Rect,
             ALINEACION);

 end;