Delphi and DirectX Delphix (6): Allow Tdximagelist to interact with regular VCL
This example tests two questions:
1, other VCL loaded pictures can be used for tdximagelist;
2, tdximagelist in the picture can give other VCL use.
In the example, first load the picture with Tpicture, then give the tdximagelist;
The picture is then drawn on the form, not in the Tdxdraw.
Continue to understand point tdximagelist:
The Tdximagelist control has only two properties: Dxdraw and Items.
Dxdraw is the destination of the image, very well understood;
Items are a collection of objects: tpicturecollection;
The Tpicturecollection collection contains a set of Tpicturecollectionitem objects;
The Tpicturecollectionitem object has a picture property, which is compatible with tpicture in other VCL!
This example uses the Tpicturecollectionitem object, the test effect diagram:
Code files:
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}
{Borrow other VCL controls to load pictures}
Procedure Tform1.formcreate (Sende R: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;
{This code looks simple, but the Code hints bad}
procedure Tform1.button1click (sender:tobject);
begin
Self.refresh;
Self.Canvas.Draw (0, 0, Dximagelist1.items[0]. Picture.graphic);
End;
{Use the Tpicturecollectionitem object for a relay, write it more smoothly}
procedure Tform1.button2click (sender:tobject);
var
picitem:tpicturecollectionitem
Begin
Self.refresh
Picitem: = Dximagelist1.items[0];
Self.Canvas.StretchDraw (Clientrect, picItem.Picture.Graphic);
End;
End.