【问题标题】:fmx delphi berlin how to change font color in rows of Tgridfmx delphi berlin如何更改Tgrid行中的字体颜色
【发布时间】:2016-10-10 10:25:55
【问题描述】:

需要帮助..我正在使用 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);

【问题讨论】:

标签: delphi fonts firemonkey delphi-10.1-berlin tgrid


【解决方案1】:

您可以在网格OnDrawColumnCell() 事件中使用FMX.Graphics.TCanvas.FillText(),而不是调用Column.DefaultDrawCell()

documentation解释了细节,但重点是在调用Canvas.FillText()之前将Canvas.Fill.Color设置为所需的颜色

示例代码:

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;

以及它的样子:

【讨论】:

  • 感谢您的解释。顺便说一句,至少从 Delphi v10.2 开始,TTextAlign.taLeading 已被弃用,请使用 TTextAlign.Leading。 taCenter 也是如此,就像现在其他人的 Center 等一样,
猜你喜欢
  • 1970-01-01
  • 2017-07-26
  • 1970-01-01
  • 1970-01-01
  • 2015-03-19
  • 2013-08-13
  • 2011-12-10
  • 2016-09-21
  • 2017-01-10
相关资源
最近更新 更多