DrawGrid 做图片显示 代码简单 参考性强 (Delphi7)
运行效果图
procedure TfrmMain.GridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var ACanvas:TCanvas; R:TRect; Bmp:TBitMap; begin ACanvas := Grid.Canvas; ACanvas.Brush.Color := clGreen; Bmp := GetPicture(ACol,ARow); if Bmp <> nil then begin R := Rect; R.Left := R.Left + 5; R.Top := R.Top + 5; R.Right := R.Right - 5; R.Bottom := R.Bottom - 5; ACanvas.StretchDraw(R,Bmp); end; end; function TfrmMain.GetPicture(ACol, ARow: Integer): TBitMap; var Index:Integer; begin Result := nil; Index := ARow * Grid.ColCount + ACol; if Index <= PicList.Count - 1 then Result := TBitMap(PicList.Items[Index]); end; procedure TfrmMain.FormCreate(Sender: TObject); var Bmp:TBitMap; Index:Integer; AFileName:string; begin PicList := TList.Create(); for Index := 1 to 18 do begin AFileName := format(ExtractFilePath(Application.ExeName) + 'Image\%d.bmp',[Index]); Bmp := TBitMap.Create(); Bmp.LoadFromFile(AFileName); PicLIst.Add(Bmp); end; end;