Ver Mensaje Individual
  #3  
Antiguo 03-12-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
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;

// Inicializar
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;

// Pintar celdas
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;

// Celda actual bajo el mouse
procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
  TStringGrid(Sender).MouseToCell(X,Y, ColRow.X, ColRow.Y);
end;

// Seleccionar color
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
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita