save imagelist

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

save imagelist

Post by sal21 »

After the imagelist is filled possible to save it, and not refill?

Code: Select all

Private Sub FILL_IMAGELIST()

    Dim NOME As String, PATH As String
    PATH = "C:\Lavori_Vb6\HOTEL\IMG\FLAG\FLAG\"

    Me.ImageList1.ListImages.Clear
    Dim FSO As New FileSystemObject
    Dim FIL As FILE, SIGLA As String, P1 As Integer

    For Each FIL In FSO.GetFolder(PATH).Files
        NOME = FIL.Name
        STATO = Replace(NOME, ".gif", "")
        Me.ImageList1.ListImages.Add , STATO, LoadPicture(PATH & NOME)
    Next

End Sub

User avatar
HansV
Administrator
Posts: 78240
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: save imagelist

Post by HansV »

I don't think so, but perhaps someone will prove me wrong.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: save imagelist

Post by SpeakEasy »

Sadly, the ImageList control does not support persistence, which means we cannot serialise it for saving to (and retrieval from) disk

Peter T
NewLounger
Posts: 18
Joined: 27 Dec 2021, 12:17

Re: save imagelist

Post by Peter T »

You can save images in an ImageList but only at design, eg

Code: Select all

Dim imgList As ImageList
    Set imgList = ThisWorkbook.VBProject.VBComponents("Userform1").Designer.ImageList1
    imgList.ListImages.Add , "img1", LoadPicture("<path>MyPic.jpg")
FWIW I don't see any reason to use an ImageList. Just as easy to save images in Image controls in a Frame or dummy form and avoid issues with older 64 bit versions of Excel, or newer versions in which the new controls havn't been added, or distributing between 'newer' 32 <> 64 bit users which messes up the reference, or aX controls n/a due to security settings.

User avatar
HansV
Administrator
Posts: 78240
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: save imagelist

Post by HansV »

Hi Peter, sal21 is developing in VB6, not in an Office application.
When adding items to a ListView control, or nodes to a TreeView control, one can specify an icon. This must be an index into an ImageList control.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: save imagelist

Post by SpeakEasy »

>You can save images

I don't think sal21 is purely interested in just saving (and loading) images - that's easy. It is all the other settings - icons, masks, background transparency colour, tags and keys - that I suspect he wants to capture all in one place.

Peter T
NewLounger
Posts: 18
Joined: 27 Dec 2021, 12:17

Re: save imagelist

Post by Peter T »

Hans and SpeakEasy,
Ah VB6, I must pay more attention before posting!
I don't have VB6 to hand but from memory most if not all those 'other settings' can also be added (and saved) at design..? (maybe the tag only manually in the dialog).
Peter T

User avatar
HansV
Administrator
Posts: 78240
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: save imagelist

Post by HansV »

Sal21 did not mention VB6 in his post, but I know it from his history of posting.

I guess he needs to populate the InageList control dynamically.
Best wishes,
Hans

Peter T
NewLounger
Posts: 18
Joined: 27 Dec 2021, 12:17

Re: save imagelist

Post by Peter T »

OK, I won't try to second-guess then ;)