Hola abelg.
Como bien te indica
Caminante, el evento que debes usar es
OnDrawCell.
Por otro lado, la clase
TStringGrid posee la propiedad vectorial
Objects que permite asociar un Objeto a cada celda, lo que la hace el candidato ideal para almacenar los colores de cada una de ellas.
Ejemplo:
Código Delphi
[-]
...
implementation
var
ColRow: TPoint;
procedure TForm1.FormCreate(Sender: TObject);
var
sg : TStringGrid;
c, r: Integer;
begin
sg := StringGrid1;
for r := sg.FixedRows to sg.RowCount-1 do
for c := sg.FixedCols to sg.ColCount - 1 do
begin
sg.Cells[c,r] := Format('Cell[%d,%d]',[c, r]);
sg.Objects[c,r] := TObject(sg.Color);
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
sg: TStringGrid;
begin
sg := TStringGrid(Sender);
if (ACol >= sg.FixedCols) and (ARow >= sg.FixedRows) then
begin
sg.Canvas.Brush.Color := TColor(sg.Objects[ACol, ARow]);
sg.Canvas.FillRect(Rect);
sg.Canvas.TextOut(Rect.Left, Rect.Top+2, sg.Cells[ACol, ARow]);
end;
end;
procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
TStringGrid(Sender).MouseToCell(X,Y, ColRow.X, ColRow.Y);
end;
procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
sg: TStringGrid;
begin
sg := TStringGrid(Sender);
if (ColRow.X >= sg.FixedCols) and (ColRow.Y >= sg.FixedRows) then
if ColorDialog1.Execute then
sg.Objects[sg.Col,sg.Row] := TObject(ColorDialog1.Color);
end;
Muestra:
Saludos