在DBGrid的如下事件中寫,每段都是一個功能
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var i: Integer;
begin
if gdSelected in State then Exit;
//隅砱桶芛腔趼极睿掖劓晇伎ㄩ
for i := 0 to (Sender as TDBGrid).Columns.Count - 1 do
begin
(Sender as TDBGrid).Columns.Title.Font.Name := '冼极'; //趼极
(Sender as TDBGrid).Columns.Title.Font.Size := 9; //趼极湮苤
(Sender as TDBGrid).Columns.Title.Font.Color := clmaroon; //趼极晇伎(綻伎)
(Sender as TDBGrid).Columns.Title.Color := clmoneygreen; //掖劓伎(蟯伎)
end;
//路俴蜊曹厙跡掖劓伎ㄩ
if Table1.RecNo mod 2 = 0 then
(Sender as TDBGrid).Canvas.Brush.Color := clInfoBk //隅砱掖劓晇伎
else
(Sender as TDBGrid).Canvas.Brush.Color := RGB(191, 255, 223); //隅砱掖劓晇伎
//隅砱厙跡盄腔晇伎ㄩ
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
with (Sender as TDBGrid).Canvas do //賒 cell 腔晚遺
begin
Pen.Color := $00FF0000; //隅砱賒捩晇伎(懦伎)
MoveTo(Rect.Left, Rect.Bottom); //賒捩隅弇
LineTo(Rect.Right, Rect.Bottom); //賒懦伎腔筵盄
Pen.Color := $0000FF00; //隅砱賒捩晇伎(蟯伎)
MoveTo(Rect.Right, Rect.Top); //賒捩隅弇
LineTo(Rect.Right, Rect.Bottom); //賒蟯伎腔旳盄
end;
//載擂囀蜊曹跪俴趼极腔晇伎
if length(Table1.Fields[3].AsString) > 6 then
DBGrid1.Canvas.Font.Color := clBlue
else if length(Table1.Fields[3].AsString) = 0 then
DBGrid1.Canvas.Font.Color := clred ;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
//妗珋厙跡腔杅蹈睿髒杅蹈煦梗眕祥肮腔晇伎珆尨眕梗眈邁腔杅擂蹈﹝
Case DataCol Mod 2 = 0 of
True: DbGrid1.Canvas.Brush.Color:= clWindow; //file://髒杅蹈蚚懦伎
False: DbGrid1.Canvas.Brush.Color:= clinfobk; //file://杅蹈蚚蟯伎
End;
DbGrid1.Canvas.Pen.Mode:=pmMask;
DbGrid1.DefaultDrawColumnCell (Rect,DataCol,Column,State);
end;