Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Cambiar fuente de texto en celdas de StringGrid (https://www.clubdelphi.com/foros/showthread.php?t=72763)

ander 10-03-2011 16:24:26

Cambiar fuente de texto en celdas de StringGrid
 
Hola a todos.
Podria decirme alguien, como podria cambiar en un StringGrid y en una columna determinada,el color de la celda y el tipo de texto.
por ej. uso esto:
-----------------------------------------------------------------
Código Delphi [-]
procedure TForm1.StringGridDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  TheRect :TRect;
begin
  if ACol=3 then
  begin
    TheRect :=StringGrid.CellRect(ACol,Arow);
    StringGrid.Canvas.TextRect(TheRect,1,1,'Hola');
    StringGrid.Canvas.brush.Color := clred;
    StringGrid.Canvas.FrameRect(TheRect);
  end;
end;
----------------------------------------------------------------
No hay manera de escribir el texto dentro de la celda,pero puedo colorearlo.
Gracias de antemano

Chris 10-03-2011 16:31:51

Con el objeto canvas del StringGrid, por ejemplo así:

Código Delphi [-]
StringGrid.Canvas.Font.Color := clRed;
StringGrid.Canvas.Font.Font = 'Arial';
// para el fondo
StringGrid.Canvas.Brush.Color := clYellow
StringGrid.Canvas.Brush.Style := bsSolid;
// etc...

Saludos!

ander 11-03-2011 09:20:33

Cambiar fuente de texto en celdas de StringGrid
 
Gracias por la respuesta, pero por más que cambio las posiciones y demas ,no hay manera de que vea en la celda y dentro del rectangulo creado el texto,y no se que hacer.
Ahora mismo, lo he dejado así y me escribe un rectángulo dentro de la celda pero no aparece el texto.
Código Delphi [-]
procedure TForm1.StringGridDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  TheRect :TRect;
begin
  if ACol=3 then
  begin
    TheRect :=StringGrid.CellRect(ACol,Arow);
    StringGrid.Canvas.Font.Color := clRed;
    StringGrid.Canvas.font.Style := Entrada_Datos.canvas.Font.Style + [fsBold];
    StringGrid.Canvas.Brush.Color := clYellow ;
    StringGrid.Canvas.Brush.Style := bsSolid;
    StringGrid.Canvas.TextRect(TheRect,1,1,'Hola');
    StringGrid.Canvas.FrameRect(TheRect);
  end;
end;

Neftali [Germán.Estévez] 11-03-2011 12:45:44

En mi web hay una entrada antigua titulada Color y alineación en celdas de un StringGrid, donde puedes ver el código del evento OnDrawCell; En ese caso se cambian los colores y se pinta el texto (de forma similar a como lo haces tú).
Si añades el cambio de fuente debería fucionar sin problemas.

Échale un vistazo al código y prueba a cambiarlo.

ander 11-03-2011 14:01:05

Gracias por el ejemplo,es todo lo que necesitaba


La franja horaria es GMT +2. Ahora son las 17:30:40.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi