2016-03-15 32 views
3

今天我的問題是關於在組件中創建PNG圖像的集合。 我發現一個按鈕,接受PNG圖像作爲gliph,但它使用的圖像的四種狀態是這樣構成的PNG圖片:組件中的Delphi PNG圖像集合

enter image description here

我已經修改了組件的採用四型動物圖像,每一個爲一個單一的國家。所以,我的組件看起來是這樣的:

... 
    public 
    FPngImgEnabled: TPngImage; 
    FPngImgDisabled: TPngImage; 
    FPngImgDown: TPngImage; 
    FPngImgOver: TPngImage; 
    FDown: Boolean; 
    Constructor Create(AOwner: TComponent); override; 
    Destructor Destroy; override; 
    procedure Paint; override; 
    published 
    property PngImgEnabled: TPngImage read FPngImgEnabled write SetPngImgEnabled; 
    property PngImgDisabled: TPngImage read FPngImgDisabled write SetPngImgDisabled; 
    property PngImgDown: TPngImage read FPngImgDown write SetPngImgDown; 
    property PngImgOver: TPngImage read FPngImgOver write SetPngImgOver; 
    ... 

是這樣,我有一個部件有四個PNG圖像,然後SetPng ...程序。我想知道是否有辦法使用四個PNG圖像的集合;像「TPNGImagesList」,用於將圖像集中在一個地方。

+1

有什麼錯了'TImageList'? – fantaghirocco

+1

[PngComponents](https://code.google.com/archive/p/cubicexplorer/downloads)中包含TPngImageList。也許這符合你的需求。也許還有一個現成的按鈕 - 我沒有檢查過。 –

+1

伴隨着:TPNGImageList有什麼問題?順便說一句,哪個Delphi版本? –

回答

1

我想你需要的東西是這樣的:

type 
    TImgType = (itEnabled, itDisabled, itDown, itOver); 


    ... 
    protected 
    procedure SetImg(Index: TImgType; Value: TPngImage); 
    function GetImg(Index: TImgType): TPngImage;  
    public 
    FImages: TList<TPngImage>; 
    FDown: Boolean; 
    Constructor Create(AOwner: TComponent); override; 
    Destructor Destroy; override; 
    procedure Paint; override; 
    published 
    property Image[Index:TImgType]: TPngImage read GetImg write SetImg; 
    property PngImgEnabled: TPngImage index itEnabled read GetImg write SetImg; 
    property PngImgDisabled: TPngImage index itDisabled read GetImg write SetImg; 
    property PngImgDown: TPngImage index itDown read GetImg write SetImg; 
    property PngImgOver: TPngImage index itOver read GetImg write SetImg; 

    ...