IGxImageList.Add

Syntax

Add(Image: IGxBitmap; [Transparent: IGxColor = Null]);

Parameters

Image. Image to be added to the collection.

Transparent. Optional parameter that determines the color that is used as a transparent one.

Description

The Add method adds the image passed by the Image parameter to the collection of images.

Fore Example

Executing the example requires a form with the button named Button1, the ImageList non-visual component named ImageList1, the TreeList component named TreeList1. Add images to the ImageList component and determine a link with the source of the ImageList1 image collection in the StateImages and Images properties of the TreeList component. Create five elements in the TreeList component and determine icons to them from the collection of images. The file system should also contain the image: C:\1.bmp. At least five icons should be in the collection and in the image. Add links to the Drawing, Forms, Io system assemblies.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    ImgList: IGxImageList;
    Str: IIOStream;
    Color: IGxColor;
Begin
    Color := GxColor.FromKnownColor(GxKnownColor.White);
    // Create a collection of images and add icons from file
    ImgList := New GxImageList.Create;
    ImgList.Add(New GxBitmap.CreateFromFile("C:\1.bmp"), Color);
    // Replace icons in the component with collection of images via the stream
    Str := New MemoryStream.Create;
    ImgList.SaveToStream(Str, Color);
    ImageList1.LoadFromStream(Str, Color);
End Sub Button1OnClick;

After executing the example clicking the button in the TreeList component replaces the added icons with the icons from the specified file C:\1.bmp.

Fore.NET Example

Executing the example requires a form with two buttons named Button1 and Button2, the ImageListNet non-visual component named imageListNet1, the TreeListNet component named treeListNet1. Determine the Images property in the TreeListNet component to create a link with the imageListNet1 image collection source and add five elements to the Nodes property. The file system should contain the following images: C:\1.bmp, C:\2.bmp, C:\3.bmp, C:\4.bmp, C:\5.bmp, C:\6.bmp. The C:\6.bmp image should contain at least five icons. Add a link to the System.IO .NET assembly and to the Drawing, Forms, Forms.NET, Metabase system assemblies.

Imports Prognoz.Platform.Forms.Net;
Imports Prognoz.Platform.Interop.Drawing;
Imports Prognoz.Platform.Interop.Forms;
Imports Prognoz.Platform.Interop.Metabase;
Imports System.IO;

Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
Var
    ImgList: IGxImageList;
    Str: Stream;
    Color: GxColor;
    BM: GXBitmap;
    il: IImageList;
    I: ITreeListNode;
Begin
    Color := New GxColorClassClass().FromName("White");
    Str := New MemoryStream.Create();
    BM := New GxBitmap();
    ImgList := New GxImageList.Create();
    // Add icons to the image collection
    ImgList.LoadFromFile("C:\1.bmp", Color);
    BM.CreateFromFile("C:\2.bmp");
    ImgList.Add(BM, Color);
    BM.CreateFromFile("C:\3.bmp");
    ImgList.Add(BM, Color);
    BM.CreateFromFile("C:\4.bmp");
    ImgList.Add(BM, Color);
    BM.CreateFromFile("C:\5.bmp");
    ImgList.Add(BM, Color);
    // Send icons via the stream to the ImageListNet component
    ImgList.SaveToStream(str, Color);
    il := (ImageListNet1.Component As IImageList);
    il.LoadFromStream(str, Color);
    // Add icons from ImageListNet  to the TreeListNet component element
    TreeListNet1.CtrlBox.Images := imageListNet1.Component As Prognoz.Platform.Interop.Forms.ImageList;
    For Each I In TreeListNet1.ForeNodes Do
        I.ImageIndex := I.Index;
    End For;
End Sub;

Private Sub button2_Click(sender: System.Object; e: System.EventArgs);
Var
    ImgList: IGxImageList;
    Str: Stream;
    Color: GxColor;
    BM: GXBitmap;
    il: IImageList;
Begin
    Color := New GxColorClassClass().FromName("White");
    // Create a new collection of images and add icons from file
    ImgList := New GxImageList.Create();
    BM := New GxBitmap();
    BM.CreateFromFile("C:\6.bmp");
    ImgList.Add(BM, Color);
    // Replace icons in the component with collection of images via the stream
    Str := New MemoryStream.Create();
    ImgList.SaveToStream(Str, Color);
    il := (imageListNet1.Component As IImageList);
    il.LoadFromStream(str, Color);
    TreeListNet1.CtrlBox.Images := imageListNet1.Component As Prognoz.Platform.Interop.Forms.ImageList;
End Sub;

After executing the example clicking the first button displays the specified icons in the TreeList component:

Clicking the second button replaces the icons with the icons from the C:\6.bmp file:

See  also:

IGxImageList