DrawGridは画像表示コードを作るのが簡単で参考性が強い(Delphi 7)

3998 ワード


運転効果図
ソース
http://files.cnblogs.com/lwm8246/DrawGrid_demo.rar
 
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;
 
DrawGrid 做图片显示 代码简单 参考性强 (Delphi7)