本例测试了两个问题:
1、其他 VCL 加载的图片能否给 TDXImageList 使用;
2、TDXImageList 中的图片能否给其他 VCL 使用.

例子中先用 TPicture 加载了图片, 然后给 TDXImageList;
然后把图片绘制在了窗体上, 而非 TDXDraw 中.

继续了解点 TDXImageList:
TDXImageList 控件只有两个属性: DXDraw 和 Items.
DXDraw 是图像的目的地, 很好理解;
Items 是一个对象集合: TPictureCollection;
TPictureCollection 集合中包含的是一组 TPictureCollectionItem 对象;
TPictureCollectionItem 对象有 Picture 属性, 这和其他 VCL 中的 TPicture 兼容!

本例用到了 TPictureCollectionItem 对象, 测试效果图:



代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DXDraws, StdCtrls;

type
  TForm1 = class(TForm)
    DXImageList1: TDXImageList;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{借用其他 VCL 控件加载图片}
procedure TForm1.FormCreate(Sender: TObject);
var
  pic: TPicture;
begin
  pic := TPicture.Create;
  pic.LoadFromFile('c:\Temp\Test.bmp');
  DXImageList1.Items.Add;
  DXImageList1.Items[0].Picture.Assign(pic);
  pic.Free;
end;

{这个代码貌似简单, 但代码提示不好}
procedure TForm1.Button1Click(Sender: TObject);
begin
  Self.Refresh;
  Self.Canvas.Draw(0, 0, DXImageList1.Items[0].Picture.Graphic);
end;

{使用 TPictureCollectionItem 对象中转一下, 写起来更顺手}
procedure TForm1.Button2Click(Sender: TObject);
var
  picItem: TPictureCollectionItem;
begin
  Self.Refresh;
  picItem := DXImageList1.Items[0];
  Self.Canvas.StretchDraw(ClientRect, picItem.Picture.Graphic);
end;

end.


posted on 2009-01-12 22:58  万一  阅读(2836)  评论(0编辑  收藏  举报