Ver Mensaje Individual
  #5  
Antiguo 06-07-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 pokexperto1.
Cita:
Empezado por pokexperto1 Ver Mensaje
... Quiero que al hacer click en una celda esa celda se coloree...Como lo hago
Un ejemplo con TStringGrid:
Código Delphi [-]
...
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); // color por defecto
        Cells[c, f]  := IntToStr(c+f);   // algo de texto
      end;
  end;
end;

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

// Botón izquierdo pinta, derecho cambia el color
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;

Muestra:


Saludos
__________________
Daniel Didriksen

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