Pintado de líneas en un StringGrid

2915 vistas

Este código permite obtener una rejilla con las lÃenas de colores diferentes. Esto facilita la lectura de rejillas con tamaños grandes.



delphi
  1. procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  2.   Rect: TRect; State: TGridDrawState);
  3. begin
  4.   with Sender as TStringGrid do with Canvas do
  5.   begin
  6.     { selección del color de fondo }
  7.     if gdFixed in State then Brush.Color := clBtnFace
  8.     else
  9.       if gdSelected in State then Brush.Color := clNavy
  10.       else
  11.         if Odd(ARow) then Brush.Color := $FFE0FF
  12.         else Brush.Color := $FFFFE0;
  13.  
  14.     { pintado del fondo }
  15.     FillRect(Rect);
  16.  
  17.     { selección del color de escritura }
  18.     if gdSelected in State then Font.Color:=clWhite
  19.     else Font.Color := clBlack;
  20.    
  21.     { dibujado del texto }
  22.     TextOut(Rect.Left, Rect.Top, Cells[ACol, ARow]);
  23.   End;
  24. end;