After creating a project, add dxdraw1 and dximagelist1 on the form;
Then you only need the following four linesCodeThe delphix. dxg image can be displayed in dxdraw1:
Procedure tform1.button1click (Sender: tobject); begin dximagelist1.items. loadfromfile ('C: \ temp \ delphix. dxg'); dximagelist1.dxdraw: = dxdraw1; dximagelist1.items [0]. draw (dxdraw1.surface, 10, 10, 0); dxdraw1.flip; end;
If you do not have an image in dxg format, download the image used in this example (download and decompress it to c: \ temp \):
Http://files.cnblogs.com/del/DelphiX_img.rar
Dximagelist1 is an image list, which is easy to add with loadfromfile, but this command is not easy to use now;
But it doesn't matter. There are other ways to create an image list:
1. Double-click the dximagelist1 icon when designing... this method is not good. Currently, only dxg and part of BMP are supported (I did not try DIB );
2. Double-click the items attribute from dximagelist1... this method is good and supports many formats;
3. Does tdximagelist always belong to the VCL control? It can interact with other VCL, and can be used as long as other widgets can load images.
The following example uses the second method to add two images and run:
Code file:
unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, dxdraws, dxclass; type tform1 = Class (tform) dxdraw1: Upload; usage: Compute; button1: tbutton; button2: tbutton; Procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject ); procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} {specifies the dxdraw attribute of dximagelist1 as dxdraw1} procedure tform1.formcreate (Sender: tobject); begin dximagelist1.dxdraw: = dxdraw1; {this step is easy to ignore; you can also specify} end; {the first image in the display list} procedure tform1.button1click (Sender: tobject) during design ); the parameter 1 of the begin {draw function is the drawing surface} {parameter 2 and 3 are coordinates} {parameter 4 is used to specify the first palette. Currently, there is only one palette by default, it can only be 0} dximagelist1.items [0]. draw (dxdraw1.surface, 10, 10, 0); dxdraw1.flip; end; {display the second image in the list} procedure tform1.button2click (Sender: tobject); begin dximagelist1.items [1]. draw (dxdraw1.surface, 10, 10, 0); dxdraw1.flip; end.