分太少,没吸引力;
唉,今天做件好事算了。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, DBGrids, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
DBGrid1: TDBGrid;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if sender is TDBGrid then
begin
with TDBGrid(Sender) do
begin
if DataSource.DataSet.RecNo mod 2 =0 then
Canvas.Brush.Color:= clYellow
else
Canvas.Brush.Color:= clPurple;
DefaultDrawColumnCell(Rect,DataCol,column,state);
end;
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if ARow mod 2 = 0 then
StringGrid1.Canvas.Brush.Color:= clYellow
else
StringGrid1.Canvas.Brush.Color:= clPurple;
StringGrid1.Canvas.FillRect(Rect);
StringGrid1.Canvas.TextOut(Rect.Left,rect.Top,StringGrid1.Cells[acol,arow]);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i,j: integer;
begin
StringGrid1.RowCount:= 5;
StringGrid1.ColCount:= 4;
for i:= 0 to StringGrid1.RowCount-1 do
for j:=0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[j,i]:= inttostr(i)+';'+inttostr(j);
end;
end.