unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (acol=1) and (arow=2) then
begin
StringGrid1.Canvas.Font.Color:=clred;
StringGrid1.Canvas.Brush.Color:=clyellow;
StringGrid1.Canvas.TextRect(Rect,Rect.Left,Rect.Top,StringGrid1.Cells[Acol,arow]);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var
i,j : integer;
begin
StringGrid1.RowCount:=5;
StringGrid1.ColCount:=5;
for i:=0 to 4 do
for j:= 0 to 4 do
StringGrid1.Cells[i,j]:=inttostr(i*j);
end;end.
这是个改变颜色的例子,
其后点击的条件你自己加进去,并在onclick中调用
stringgrid1.Invalidate
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (acol=1) and (arow=2) then
begin
StringGrid1.Canvas.Font.Color:=clred;
StringGrid1.Canvas.Brush.Color:=clyellow;
StringGrid1.Canvas.TextRect(Rect,Rect.Left,Rect.Top,StringGrid1.Cells[Acol,arow]);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var
i,j : integer;
begin
StringGrid1.RowCount:=5;
StringGrid1.ColCount:=5;
for i:=0 to 4 do
for j:= 0 to 4 do
StringGrid1.Cells[i,j]:=inttostr(i*j);
end;end.
这是个改变颜色的例子,
其后点击的条件你自己加进去,并在onclick中调用
stringgrid1.Invalidate
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货