DrawGrid图形填充 ( 积分: 300 )

  • 主题发起人 主题发起人 李艾
  • 开始时间 开始时间

李艾

Unregistered / Unconfirmed
GUEST, unregistred user!
当点击一个按钮,在DrawGrid里填充不同的图形。怎么填,分不够再加。在线等。
 
在TDrawGrid的OnDrawCell事件中:

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
Bmp: TBitmap;
begin
case ACol of
0:
begin
Bmp := TBitmap.Create;
Bmp.LoadFromFile('./0.bmp');
Canvas.StretchDraw(Rect, Bmp);
Bmp.Free;
end;
1:
begin
Bmp := TBitmap.Create;
Bmp.LoadFromFile('./1.bmp');
Canvas.StretchDraw(Rect, Bmp);
Bmp.Free;
end;
end;
end;
 
一个一个填有办法吗?
 
OK了,参考Miros是可以,但不是很完整,感谢他!分全给他了。
 
private
{ Private declarations }
public
f:Integer;
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var
bRect:TRect;
State:TGridDrawState;
begin
f:=1;
bRect:=DrawGrid1.CellRect(0,0);
DrawGrid1DrawCell(TObject(DrawGrid1),0,0,bRect,State);
end;

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);

var
Bmp: TBitmap;
Str1:string;
i:Integer;
re:TRect;
begin
if f=1 then
begin
ACol:=0;
ARow:=0;
Str1:='123456789';
for i:=1 to Length(Str1) do
begin
//if (ACol=j) and (ARow=k) then
begin
DrawGrid1.Update;
re:=DrawGrid1.CellRect(arow,acol);
//ShowMessage(IntToStr(acol)+' '+IntToStr(arow));
Bmp:=TBitmap.Create;
Bmp.LoadFromFile('D:/test/新建文件夹/imgs/a'+copy(Str1,i,1)+'.bmp');
DrawGrid1.Canvas.StretchDraw(re,bmp);
Bmp.Free;
if acol>=4 then
begin
Inc(ARow);
ACol:=0;
end
else
begin
Inc(ACol);
end;

end;
end;
end;
// case ACol of
// 0:
// begin
// Bmp := TBitmap.Create;
// Bmp.LoadFromFile('D:/test/新建文件夹/imgs/ma_03.bmp');
// DrawGrid1.Canvas.StretchDraw(Rect, Bmp);
// Bmp.Free;
// end;
// 1:
// begin
// Bmp := TBitmap.Create;
// Bmp.LoadFromFile('D:/test/新建文件夹/imgs/ma_05.bmp');
// DrawGrid1.Canvas.StretchDraw(Rect, Bmp);
// Bmp.Free;
// end;
// end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
f:=0;
end;
 
后退
顶部