unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//wypełnienie tabeli liczbami losowymi
procedure TForm1.BitBtn1Click(Sender: TObject);
var
  I, J : Integer;
begin
  with StringGrid1 do
    for I := 0 to ColCount - 1 do
      for J:= 0 to RowCount - 1 do
        Cells[I,J] := IntToStr(Random(2001));
  StringGrid1.SetFocus;

end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
//zmiana koloru czcionki w parzystych kolumnach na niebieski, w nieparzystych na ĺzielony
//zawartość komórek wyrównana standardowo do lewej
 with Stringgrid1 do
  with Rect do
  if ACol mod 2=0 then  //czy numer kolumny parzysty
  begin
    Canvas.Font.Color:=clBlue;
    Canvas.FillRect(Rect);
    Canvas.TextOut(Left+2, Top+2,Cells[ACol,ARow]);
  end
  else
  begin
    Canvas.Font.Color:=clLime;
    Canvas.FillRect(Rect);
    Canvas.TextOut(Left+ 2, Top+2,Cells[ACol,ARow]);
  end

end;

end.
