gpt4 book ai didi

delphi - 在单元格中输入数据时,更改StringGrid的单元格颜色。德尔菲

转载 作者:行者123 更新时间:2023-12-03 19:23:44 26 4
gpt4 key购买 nike

晚上好,我想知道在写入数据时如何更改单元格的颜色

我有这个...

procedure TFrmReportes.SGDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin

if (gdSelected in State) then
begin
SG.Canvas.Brush.Color := rgb(255,119,119);
SG.Canvas.FillRect(SG.CellRect(ACol, ARow));
SG.Canvas.TextOut(Rect.Left+2,Rect.Top+2, SG.Cells[ACol, ARow]);

end;
end;


但是当在单元格中输入数据时,它变成白色

再次感谢!!!

最佳答案

TStringGrid在当前正在编辑的单元格顶部显示TInplaceEditTInplaceEdit覆盖整个单元格。这就是为什么您看不到自定义图纸的原因。您将需要更改TInplaceEditColor属性。您可以通过TInplaceEdit属性访问TStringGrid.InplaceEditor

我建议从TStringGrid派生一个新组件,并重写其虚拟CreateEditor()方法。如果您的表单中只有1个网格,那么一个简单的插入器就足够了,例如:

type
TStringGrid = class(Vcl.Grids.TStringGrid)
protected
function CreateEditor: TInplaceEdit; override;
end;

TFrmReportes = class(TForm)
SG: TStringGrid;
...
end;

...

type
TInplaceEditAccess = class(TInplaceEdit)
end;

function TStringGrid.CreateEditor: TInplaceEdit;
begin
Result := inherited CreateEditor;
TInplaceEditAccess(Result).Color := RGB(255, 119, 119);
end;

关于delphi - 在单元格中输入数据时,更改StringGrid的单元格颜色。德尔菲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59097731/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com