WPImageList as ImageList
|Top Previous Next|
A) Use bitmaps from TWPImageList in TImageList
The WPImageList can also populate a standard TImageList. To do so assign the property LinkedImageList and call UpdateLinkedList in code or in the designer in the context menu.
You can also call FillImageList(destinationlist) in code to fill any image list.
B) Use TWPImageList as TImageList
Starting with Delphi 10.3 it is possible to inherit a new image list of the standard TImageList. We adapted this technology and make it possible to use a WPImageList also for standard menu items, buttons and actions.
This option is activated by the $DEFINE WPCUSTOMIMG in unit wputil.pas.
In this demo we use this feature:
The TWPToolButton can use the images in the WPImageList directly.
To make the other controls use the images, we assign the WPImageList to the images property of the various controls in OnCreate:
procedure TForm1.FormCreate(Sender: TObject);
// this requires Delphi 10.3 and WPTools 9
MainMenu1.Images := WPImageList1;
ActionList1.Images := WPImageList1;
ToolBar1.Images := WPImageList1;
Button1.Images := WPImageList1;
Button2.Images := WPImageList1;
WPImageList1.UseAsImagelist := true;
Please note that UseAsImageList must be set to true. The property WPImageList.Width and -Height must be also set. They define the width and height of the virtual images which are created from the PNG list to be used by the other controls. (Unfortunately not all controls support the DoDraw function which can be overridden in the ImageList concept, so a virtual image list is created temporarily.)
With the above initialization this is how the program looks at runtime:
The green rectangle is a paint box - it calls the DrawImage function of the TWPImageList. The drawing code will automatically select the image which has the best resolution for the output.
procedure TForm1.PaintBox1Paint(Sender: TObject);
PaintBox1.Canvas.Pen.Width := 0;
PaintBox1.Canvas.Brush.Style := bsSolid;
PaintBox1.Canvas.Brush.Color := clGreen;
PaintBox1.Canvas.Rectangle(1,1, PaintBox1.Width-2, PaintBox1.Height-3 );
PaintBox1.Canvas.Brush.Style := bsClear;
WPImageList1.DrawImage( PaintBox1.Canvas, 0,0, PaintBox1.Width, PaintBox1.Height, true, true, 1);