![](/img/trans.png)
[英]How to change color of a cell in a Delphi TGrid Firemonkey component?
[英]fmx delphi berlin how to change font color in rows of Tgrid
需要幫助..我正在使用delphi 10.1柏林。 與其他先前版本的Embarcadero Delphy Code Gear有所不同。 我需要更改TGrid行中的字體顏色。 下一個代碼我將更改背景色,但我只需要更改字體顏色:
aRowColor.Color := arSTATUS_GRID_COLOR[0];
Canvas.FillRect(Bounds, 0, 0, [], 1, aRowColor);
Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
您可以在網格OnDrawColumnCell()
事件中使用FMX.Graphics.TCanvas.FillText()
而不是調用Column.DefaultDrawCell()
。
該文檔解釋了細節,但主要的一點是設置Canvas.Fill.Color
之前調用所需顏色Canvas.FillText()
樣例代碼:
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;
以及它的樣子:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.