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

时光毁灭记忆、已成空白 提交于 2019-12-11 00:38:28

问题


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);

回答1:


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:



来源:https://stackoverflow.com/questions/39956166/fmx-delphi-berlin-how-to-change-font-color-in-rows-of-tgrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!