求教 (100分)

  • 主题发起人 主题发起人 tylhx
  • 开始时间 开始时间
T

tylhx

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手:
我如何改变DBGrid中高亮条的颜色(蓝变绿),请指教?
[green][/green]
 
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumn;
State: TGridDrawState);
begin
if gdSelected in State then
dbgrid1.Canvas.Brush.Color := clGreen
else
dbgrid1.Canvas.Brush.Color := clWhite;
dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
 
procedure TfrmSQLMain.grdMainDrawDataCell(Sender: TObject;
const Rect: TRect;
Field: TField;
State: TGridDrawState);
begin
if gdSelected in State then
//如果当前行为选中状态
begin
grdMain.Canvas.Brush.Color := clNavy;
//背景为蓝色
grdMain.Canvas.Font.Color := clWhite;
//文字为白色
end
else
if DMConn.adsEdit.RecNo mod 2 = 0 then
//如果是双数行
begin
grdMain.Canvas.Brush.Color := $00EDDADA;
//$00EDDADA也是颜色, 只是Delphi无定义成常量
grdMain.Canvas.Font.Color := clBlack;
end
else
begin
//如果是单数行
grdMain.Canvas.Brush.Color := clWhite;
grdMain.Canvas.Font.Color := clBlack;
end;
grdMain.Canvas.FillRect(Rect);
//画一个长方形的背景
grdMain.Canvas.TextOut(Rect.Left + 3, Rect.Top + 2, Field.AsString);
//把文字画上去
end;
 
接受答案了.
 
后退
顶部