[在单元格中输入数据时更改StringGrid的单元格颜色。德尔福

问题描述 投票:1回答:2

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

我有这个...

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;

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

再次感谢!!

delphi
2个回答
4
投票

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

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

TStringGrid

0
投票

由于您在上一个示例中的建议,我找到了以下对我有用的代码使用InplaceEditor属性

CreateEditor()

非常感谢

© www.soinside.com 2019 - 2024. All rights reserved.