DELPHI 10.3.3环境下,因为个人需要对表格根据单元格的复制内容判断来设置指定文字颜色,在网上搜索了大多数是TStringGrid、DBGrid、cxGrid之类的,而且新版DELPHI10以上的比较少,根据实际调试使用,在DELPHI10.3.3通过以下测试代码:
具体通过处理GRID的Grid1DrawColumnCell()事件来增加代码实现。
//FMX 中设置GRID某列中的内容显示背景颜
procedure Tfmtel.Grid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const Bounds: TRectF; const Row: Integer;
const Value: TValue; const State: TGridDrawStates);
begin
bgBrush:=TBrush.Create(TBrushKind.Solid,TAlphaColors.White);//定义缺省颜色
try
if Column.Index=3 then
begin
if trim(Value.ToString)='卖出' then
begin
bgBrush.Color := TAlphaColors.Palegreen;
Canvas.FillRect(Bounds,0,0,[],1,bgBrush);
end
else
begin
bgBrush.Color := TAlphaColors.Pink;
Canvas.FillRect(Bounds,0,0,[],1,bgB