更改 DBGrid 行的颜色
Change color of DBGrid row
如何更改最新的 rec 颜色 dbgrid?
if (Sender as TDBGrid).DataSource.DataSet.RecNo = (Sender as TDBGrid)
.DataSource.DataSet.RecordCount then
begin
Canvas.Brush.Color := [=10=]C66F71;
end;
(Sender as TDBGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);
使用 OnDrawColumnCell
属性 共 TDbGrid
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:=[=10=]C66F71;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
要更改文本颜色,请使用:
DBGrid1.Canvas.Font.Color:=clRed;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
在你的代码中
Canvas.Brush.Color:=[=12=]C66F71;
是 TForm
的 Canvas
,而不是 TDbgrid
的 Canvas
如何更改最新的 rec 颜色 dbgrid?
if (Sender as TDBGrid).DataSource.DataSet.RecNo = (Sender as TDBGrid)
.DataSource.DataSet.RecordCount then
begin
Canvas.Brush.Color := [=10=]C66F71;
end;
(Sender as TDBGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);
使用 OnDrawColumnCell
属性 共 TDbGrid
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:=[=10=]C66F71;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
要更改文本颜色,请使用:
DBGrid1.Canvas.Font.Color:=clRed;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
在你的代码中
Canvas.Brush.Color:=[=12=]C66F71;
是 TForm
的 Canvas
,而不是 TDbgrid
Canvas