fmx delphi berlin how to change font color in rows of Tgrid
Asked Answered
G

1

2

NEED HELP..I am using delphi 10.1 berlin. There are some different with other previus version of Embarcadero Delphy Code Gear. I need to change font color in rows of TGrid. Whith this next code i will change backgrond color but i need to change only Font Color :

  aRowColor.Color := arSTATUS_GRID_COLOR[0];
  Canvas.FillRect(Bounds, 0, 0, [], 1, aRowColor);
  Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
Gocart answered 10/10, 2016 at 10:25 Comment(1)
See this cuestion: #32887519 or this: #22095914Pimp
D
5

Instead of calling Column.DefaultDrawCell(), you can use FMX.Graphics.TCanvas.FillText() in the grids OnDrawColumnCell() event.

The documentation explains the details, but the main point is to set Canvas.Fill.Color to the desired color before calling Canvas.FillText()

Sample code:

procedure TForm28.Grid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
  const Column: TColumn; const Bounds: TRectF; const Row: Integer;
  const Value: TValue; const State: TGridDrawStates);
begin
  case Row of
    0: Canvas.Fill.Color := TAlphaColors.Red;
    1: Canvas.Fill.Color := TAlphaColors.Blue;
    2: Canvas.Fill.Color := TAlphaColors.Green;
    3: Canvas.Fill.Color := TAlphaColors.Blueviolet;
  end;
  Canvas.FillText(Bounds, Value.AsString, false, 1, [], TTextAlign.Leading, TTextAlign.Center);
end;

And how it looks like:

enter image description here

Dragrope answered 11/10, 2016 at 11:41 Comment(1)
Thanks for the explanation. BTW, as of at least Delphi v10.2 TTextAlign.taLeading has been deprecated, use TTextAlign.Leading. The same goes for taCenter as now just Center and etc for others,Erb

© 2022 - 2024 — McMap. All rights reserved.