unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;
type
TForm1 =
class(TForm)
Grid: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure GridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
iCol : Integer;
iRow : Integer;
begin
for iCol:= 0
to Grid.ColCount-1
do
begin
for iRow:= 0
to Grid.RowCount-1
do
begin
Grid.Cells[iCol,iRow]:= IntToStr(iCol);
end;
end;
end;
procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if Grid.Cells[ACol,ARow]='
0'
then
begin
Grid.Canvas.Brush.Color:= clRed;
Grid.Canvas.FillRect(Rect);
end
else
begin
Grid.Canvas.Brush.Color:= clBlue;
Grid.Canvas.FillRect(Rect);
end;
Inc(Rect.Left,2);
DrawText(Grid.Canvas.Handle, PChar(Grid.Cells[ACol,ARow]),
Length(Grid.Cells[ACol,ARow]), Rect,
DT_END_ELLIPSIS
or DT_NOPREFIX);
end;