这是一个StringGrid里设某一单元格颜色的,
我想应该和DBGridEh基本上一样,给你作参考吧。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.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.
我想应该和DBGridEh基本上一样,给你作参考吧。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.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.
Background := $00FFC4C4
else
Background := $00FFDDDD;颜色自己去慢慢调整吧,给分吧!