Rub*_*ube 2 delphi background-color firemonkey stringgrid delphi-10.1-berlin
我在 Delphi 10.1 的多设备应用程序(在 Windows 上)中遇到问题。我有一个StringGrid(连接到数据库),我可以更改行的背景颜色,但问题是单元格之间有“填充”(灰色/银色)。
在onformCreate我定义中:
stringgrid1.DefaultDrawing := False;
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
procedure Tlist_form.StringGrid1DrawColumnCell(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var aRowColor: TBrush;
begin
aRowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha);
if (stringgrid1.Cells[7,row]='1') then
aRowColor.Color := TAlphaColors.Green
else
aRowColor.Color := TAlphaColors.Red;
Canvas.FillRect(Bounds, 0, 0, [], 1, aRowColor);
Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
aRowColor.free;
end;
Run Code Online (Sandbox Code Playgroud)
在 Delphi 6 中我从未遇到过这个问题,而且我不知道如何解决它。谢谢。
解决方案1(设计时):
对于每个属性StringColumn,找到该Padding属性并将所有值从 3 更改为 0。
解决方案 2(运行时):
将 a 添加TRectF到本地变量。为其指定值Bounds和Inlfate()it。修改后的OnDrawColumnCell()样子是这样的:
procedure TForm30.StringGrid1DrawColumnCell(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var
aRowColor: TBrush;
aNewRectF: TRectF;
begin
aRowColor := TBrush.Create(TBrushKind.Solid, TAlphaColors.Alpha);
if (StringGrid1.Cells[7, Row] = '1') then
aRowColor.Color := TAlphaColors.Green
else
aRowColor.Color := TAlphaColors.Red;
aNewRectF := Bounds;
aNewRectF.Inflate(3, 3);
Canvas.FillRect(aNewRectF, 0, 0, [], 1, aRowColor);
Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
aRowColor.free;
end;
Run Code Online (Sandbox Code Playgroud)
两种解决方案的网格如下所示:
要同时删除单元格之间的线条,请取消选中网格中的ColLines和。RowLinesOptions