procedure Tform_outplate.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with DBGrid1.Canvas do begin
if Column.Title.Caption = '出电' then
Brush.Color := clRed
else if Column.Title.Caption = '返电' then
Brush.Color := clBlue
else if Column.Title.Caption = '改电' then
Brush.Color := clWhite;
FillRect(Rect);
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;我只想改变字体的颜色,不想改变整个cell的颜色,请问怎么做?
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with DBGrid1.Canvas do begin
if Column.Title.Caption = '出电' then
Brush.Color := clRed
else if Column.Title.Caption = '返电' then
Brush.Color := clBlue
else if Column.Title.Caption = '改电' then
Brush.Color := clWhite;
FillRect(Rect);
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;我只想改变字体的颜色,不想改变整个cell的颜色,请问怎么做?
要改成这样:
with DBGrid1.Canvas do begin
if Column.Title.Caption = '出电' then
Font.Color := clRed
else if Column.Title.Caption = '返电' then
Font.Color := clBlue
else if Column.Title.Caption = '改电' then
Font.Color := clGreen;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if field.FieldName='Traffic_No' then
DBGrid1.Canvas.font.Color:=clRed;
// FillRect(Rect);
DBGrid1.DefaultDrawDataCell(Rect, Field,State);
end;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if column.FieldName='NAME' then
begin
if (dbgrid1.DataSource.DataSet.RecNo mod 2)=0 then
DbGrid1.Canvas.Brush.Color:= clAqua;
end;
If ((State = [gdSelected]) or (State=[gdSelected,gdFocused])) then
DbGrid1.Canvas.Brush.Color:= clred; DbGrid1.DefaultDrawColumnCell (Rect,DataCol,Column,State);
end;
if Column.Title.Caption = '出电' then
Canvas.Font.Color := clRed
else if Column.Title.Caption = '返电' then
Canvas.Font.Color := clBlue
else if Column.Title.Caption = '改电' then
Canvas.Font.Color := clGreen;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;