问题来源: http://www.cnblogs.com/del/archive/2008/03/06/1094289.html#2023057
在 C:\Temp\ 下准备 1.bmp、2.bmp、3.bmp 三个图片, 然后:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids; type TForm1 = class(TForm) DrawGrid1: TDrawGrid; procedure FormCreate(Sender: TObject); procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure FormDestroy(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} var bits: array[0..2] of TBitmap; procedure TForm1.FormCreate(Sender: TObject); var i: Integer; begin ChDir('c:\Temp\'); for i := Low(bits) to High(bits) do begin bits[i] := TBitmap.Create; bits[i].LoadFromFile(IntToStr(i+1) + '.bmp'); end; DrawGrid1.FixedRows := 0; DrawGrid1.FixedCols := 0; DrawGrid1.RowCount := 1; DrawGrid1.ColCount := 3; DrawGrid1.DefaultRowHeight := bits[0].Height; DrawGrid1.DefaultColWidth := bits[0].Width; end; procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var r: TRect; begin if (ARow = 0) and (ACol >= Low(bits)) and (ACol <= High(bits)) then begin r := Bounds(0, 0, bits[ACol].Width, bits[ACol].Height); //r := Bounds(0, 0, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top); TDrawGrid(Sender).Canvas.CopyRect(Rect, bits[ACol].Canvas, r); end; end; procedure TForm1.FormDestroy(Sender: TObject); var i: Integer; begin for i := Low(bits) to High(bits) do bits[i].Free; end; end.