Adds a ListImage to a ListImages collection in an ImageList control and returns a reference to the newly created ListImage object.
ImageList.Add[Item]([index], [key], picture)
ListImages.Add([index], [key], picture)
ImageList.AddPart [index], [key], [picture], [X], [Y]
index, key, picture | : Variant exp |
x, y | : iexp |
Add, AddItem, ListImages.Add, and AddPart perform the same task; they add a single image to the ListImages collection owned by the ImageList control.
You can load either bitmaps, cursors, or icons into a ListImage object. To load a bitmap or icon, you can use the LoadPicture function.
index | Optional. An integer specifying the position where you want to insert the ListImage. If no index is specified, the ListImage is added to the end of the ListImages collection. |
key | Optional. A unique string expression that can be used to access a member of the collection. |
picture | Specifies the picture to be added to the collection. |
AddPart adds a part of an image to the collection. The x, y coordinate specify the location of the piece to be grabbed from a picture. The width and the height are determined by the dimensions of the ImageList control.
Const IDI_SHIELD = 32518
Global Int32 m, n, x, y
Dim h As Handle, p As Picture
Ocx ImageList iml
iml.ImageWidth = 32
iml.ImageHeight = 32
Dim lim As ListImage
iml.ListImages.Add , "app", CreatePicture(LoadIcon(Null, IDI_APPLICATION))
iml.ListImages.Add , "info", CreatePicture(LoadIcon(Null, IDI_INFORMATION))
Set lim = iml.ListImages.Add( , "error", CreatePicture(LoadIcon(Null, IDI_ERROR)))
iml.Add , "query", CreatePicture(LoadIcon(Null, IDI_QUESTION))
iml.AddItem , "security", CreatePicture(LoadIcon(Null, IDI_SHIELD))
iml.AddPart , "winlogo", CreatePicture(LoadIcon(Null, IDI_WINLOGO))
For m = 0 To 5 : x = (m * 32) : y = (m * 32)
For n = 1 To 6
Set p = iml(n).ExtractIcon : PaintPicture p, x, y
Add y, 32 : If y > 191 Then y = 0
Next n
Next m
AddPart example:
// Loads the 36 icons in reverse order into a new ImageList...
// ...and displays them to the right of the originals
Get 0, 0, 191, 191, h
Set p = CreatePicture(h, 1)
Ocx ImageList iml1
iml1.ImageHeight = 32
iml1.ImageWidth = 32
// or could be calculated like this:
// iml1.ImageHeight = HimetsToPixelX(p.Height) / 6
// iml1.ImageWidth = HimetsToPixelX(p.Width) / 6
For n = 5 To 0 Step -1
For m = 5 To 0 Step -1
iml1.AddPart , , p, (n * 32), (m * 32)
Next m
Next n
GFA-BASIC 32 specific
Instead of explicitly using the ListImages collection to access a ListImage element, you can use a shorter notation. First, the ImageList supports an Item property:
iml.Item(idx) instead of iml.ListImages.Item(idx)
Like the Item method of iml.ListImages, Item is the default method of ImageList. Therefore, a ListImage can be accessed as follows:
iml(idx) instead of iml.ListImages(idx)
iml!idx instead of iml.ListImages!idx
Each dot saves about 30 bytes of code.
To enumerate over the ListImages collection of an ImageList Ocx, use For Each on the Ocx control directly, like:
Local lim As ListImage, iml As ImageList
For Each lim In iml : DoSomething(lim) : Next
ImageList, ListImages, ListImage
{Created by Sjouke Hamstra; Last updated: 01/12/2021 by James Gaite}