【问题标题】:Change color of DBGrid row更改 DBGrid 行的颜色
【发布时间】:2015-05-22 19:40:21
【问题描述】:

如何更改最新的记录颜色 dbgrid?

if (Sender as TDBGrid).DataSource.DataSet.RecNo = (Sender as TDBGrid)
  .DataSource.DataSet.RecordCount then
begin
  Canvas.Brush.Color := $00C66F71;
end;
(Sender as TDBGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);

【问题讨论】:

    标签: delphi delphi-7 tdbgrid


    【解决方案1】:

    使用TDbGridOnDrawColumnCell属性

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if (Sender as TDBGrid).DataSource.DataSet.RecNo = (Sender as TDBGrid).DataSource.DataSet.RecordCount then
    begin
      //change color of row    
      DBGrid1.Canvas.Brush.Color:=$00C66F71;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
    

    要更改文本的颜色,请使用:

    DBGrid1.Canvas.Font.Color:=clRed;
    DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    

    在你的代码中

    Canvas.Brush.Color:=$00C66F71;
    

    TFormCanvas,而不是TDbgridCanvas

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-31
      • 1970-01-01
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 2020-03-13
      • 1970-01-01
      相关资源
      最近更新 更多