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;

 

 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM