Delphi PNG图像集合在一个组件中

时间:2016-03-15 09:45:16

标签: delphi png delphi-xe7

今天我的问题是关于在组件中创建PNG图像的集合。 我找到了一个接受PNG图像作为gliph的按钮,但它使用由图像的四种状态组成的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 个答案:

答案 0 :(得分: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;

  ...