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

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

我有这个...

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;

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

再次感谢!

jinkaixin1980 回答:在单元格中输入数据时,更改StringGrid的单元格颜色。德尔菲

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

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

TStringGrid
,

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

type
    THackGrid = class(TCustomGrid)
    public
      property InPlaceEditor;
      property EditorMode;
    end;

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

...

procedure TFrmReportes.Button1Click(Sender: TObject);
begin
   THackGrid(SG).InPlaceEditor.Brush.Color := RGB(255,119,119);
end;

非常感谢

本文链接:https://www.f2er.com/3010460.html

大家都在问