Alineación de texto en las celdas

4800 vistas

Realizaremos este proceso usando el API de Windows



delphi
  1. procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
  2.   Rect: TRect; State: TGridDrawState);
  3. var
  4.   Grid: TStringGrid;
  5.   Texto: String;
  6. begin
  7.   Grid := TStringGrid(Sender);
  8.  
  9.   if (Row < Grid.FixedRows) or (Col < Grid.FixedCols) then
  10.     Grid.Canvas.Brush.Color := clBtnFace
  11.   else
  12.     Grid.Canvas.Brush.Color := clWhite;
  13.  
  14.   Grid.Canvas.FillRect(Rect);
  15.   Texto := Grid.Cells[Col,Row];
  16.   DrawText( Grid.Canvas.Handle, PChar(Texto), StrLen(PChar(Texto)),
  17.             Rect, DT_CENTER);
  18. end;



Recomendamos ver toda la información referente a la función DrawText del API para ver todas sus posibilidades como ahora el [iurl=85&fs=169#171]Centrado el texto en las celdas[/iurl]