C
chcsl
Unregistered / Unconfirmed
GUEST, unregistred user!
我是这样做的, 在 Form1 上放置 DBGrid1、ADOQuery1、DataSource1<br>不能通过编译,请高手指点,加下划线处请解释一下。 <br>语句如下:<br>procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject;<br>const Rect: TRect; DataCol: Integer; Column: TColumn;State: TGridDrawState);<br>var i :integer;<br>begin<br>if gdSelected in State then Exit;<br>//定义表头的字体和背景颜色:<br> for i :=0 to (Sender as TDBGrid).Columns.Count-1 do<br> begin<br> (Sender as TDBGrid).Columns.Title.Font.Name :='宋体'; //字体<br> (Sender as TDBGrid).Columns.Title.Font.Size :=9; //字体大小<br> (Sender as TDBGrid).Columns.Title.Font.Color :=$000000ff; //字体颜色(红色)<br> (Sender as TDBGrid).Columns.Title.Color :=$0000ff00; //背景色(绿色)<br> end;<br>//隔行改变网格背景色:<br>if ADOQuery1.RecNo mod 2 = 0 then<br> (Sender as TDBGrid).Canvas.Brush.Color := clInfoBk //定义背景颜色<br>else<br> (Sender as TDBGrid).Canvas.Brush.Color := RGB(191, 255, 223); //定义背景颜色<br>//定义网格线的颜色:<br> DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);<br>with (Sender as TDBGrid).Canvas do //画 cell 的边框<br>begin<br> Pen.Color := $00ff0000; //定义画笔颜色(蓝色)<br> MoveTo(Rect.Left, Rect.Bottom); //画笔定位<br> LineTo(Rect.Right, Rect.Bottom); //画蓝色的横线<br> Pen.Color := $0000ff00; //定义画笔颜色(绿色)<br> MoveTo(Rect.Right, Rect.Top); //画笔定位<br> LineTo(Rect.Right, Rect.Bottom); //画绿色的竖线<br>end;<br>end;