您拷貝就可以運行:
unit Unit1;
interface
uses
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
with StringGrid1 do
if Cells[ACol,ARow] = '1233' then
begin
Canvas.Font.Color := clred; //字體顏色為紅的
Canvas.Brush.color:=clMoneyGreen; //背景為 美元綠色
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with StringGrid1 do
begin
RowCount :=5;//設置5行
ColCount :=5;//設置5列
Cells[1,2]:='1233';
Cells[2,2]:='1233';
Cells[2,4]:='1233';
end;
end;
end.
-----------------------------------------------------
關鍵是DrawCell事件,在這個事件中可以設字體名、大小、顏色、字體裝飾、cell背景畫布等
---------------------------------------------------