...
implementation
var
PaintColor : TColor = clRed;
procedure TForm1.FormCreate(Sender: TObject);
var
c, f: Integer;
begin
with StringGrid1 do
begin
Options := Options + [goEditing];
for c := FixedCols to ColCount-1 do
for f := FixedRows to RowCount-1 do
begin
Objects[c, f]:= TObject(clWhite); Cells[c, f] := IntToStr(c+f); end;
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with TStringGrid(Sender) do
begin
if (ACo l>= FixedCols) and (ARow >= FixedRows) then
begin
Canvas.Brush.Color := TColor(Objects[ACol, ARow]);
Canvas.FillRect(Rect);
Canvas.Font.Color := clBlack;
Canvas.TextOut(Rect.Left+2, Rect.Top+2, Cells[ACol, ARow]);
end;
end;
end;
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
ACol, ARow: Integer;
begin
with TStringGrid(Sender) do
begin
MouseToCell(X, Y, ACol, ARow);
case Button of
mbLeft : Objects[ACol, ARow] := TObject(PaintColor);
mbRight: if ColorDialog1.Execute then PaintColor := ColorDialog1.Color;
end;
end;
end;