fill image list from .gif in dir

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

fill image list from .gif in dir

Post by sal21 »

Possible to fill an imagelist with a .gif in c:\mydir\img\

note:
after maintain the .gif saved in imagelist, for the next use

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

Re: fill image list from .gif in dir

Post by HansV »

Perhaps code like this:

Code: Select all

    Const strPath = "c:\mydir\img\"
    Dim strFile As String
    With Me.ImageList1.ListImages
        strFile = Dir(strPath & "*.gif")
        Do While strFile <> ""
            .Add Picture:=LoadPicture(strPath & strFile)
            strFile = Dir
        Loop
    End With
Best wishes,
Hans

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

Re: fill image list from .gif in dir

Post by sal21 »

HansV wrote:
09 Feb 2022, 15:26
Perhaps code like this:

Code: Select all

    Const strPath = "c:\mydir\img\"
    Dim strFile As String
    With Me.ImageList1.ListImages
        strFile = Dir(strPath & "*.gif")
        Do While strFile <> ""
            .Add Picture:=LoadPicture(strPath & strFile)
            strFile = Dir
        Loop
    End With
tks.

but really i need to fill a imagecombobox with a little flag of states and international phone prefix...

similar:

flag<state><prefix>

flag of Italia-ITALIA_+39

have an idea?

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

Re: fill image list from .gif in dir

Post by HansV »

Lets say :italy: has index 4 in the image list.

Me.ImageCombo1.ComboItems.Add Text:="ITALIA - 39", Image:=4
Best wishes,
Hans

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

Re: fill image list from .gif in dir

Post by sal21 »

HansV wrote:
09 Feb 2022, 16:08
Lets say :italy: has index 4 in the image list.

Me.ImageCombo1.ComboItems.Add Text:="ITALIA - 39", Image:=4
Problem...
I have The image of flag state without idetif prefix!
I have only italy.gif!!!
I need any images of states and related prefix Number,...
Can you help me for research....

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

Re: fill image list from .gif in dir

Post by HansV »

When you add the gif files to the ImageList:

Code: Select all

            .Add Picture:=LoadPicture(strPath & strFile), Key:=Replace(strFile, ".gif". "")
This will store Italy.gif with Key value "Italy".
Then use

Code: Select all

Me.ImageCombo1.ComboItems.Add Text:="ITALIA - 39", Image:="Italy"
(I cannot test this myself)
Best wishes,
Hans

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

Re: fill image list from .gif in dir

Post by HansV »

You'll find lots of flags in this post. It's not up-to-date though.
Best wishes,
Hans

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

Re: fill image list from .gif in dir

Post by HansV »

Best wishes,
Hans

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

Re: fill image list from .gif in dir

Post by sal21 »

HansV wrote:
09 Feb 2022, 19:04
Also see Best Country Flag Icon Sets
TKS.

But i need also the association flag+prefix+state

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

Re: fill image list from .gif in dir

Post by HansV »

See List of country calling codes and/or [url=https://countrycode.org/]Country Codes[/code]
Best wishes,
Hans

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

Re: fill image list from .gif in dir

Post by sal21 »

HansV wrote:
09 Feb 2022, 15:26
Perhaps code like this:

Code: Select all

    Const strPath = "c:\mydir\img\"
    Dim strFile As String
    With Me.ImageList1.ListImages
        strFile = Dir(strPath & "*.gif")
        Do While strFile <> ""
            .Add Picture:=LoadPicture(strPath & strFile)
            strFile = Dir
        Loop
    End With
RESOLVED!

but i can add a .tag when add picture?

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

Re: fill image list from .gif in dir

Post by HansV »

Individual images in an ImageList control do not have a Tag, but you can use the Key property for this purpose:

.Add Picture:=LoadPicture(strPath & strFile), Key:=Replace(strFile, ".gif". "")
Best wishes,
Hans

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

Re: fill image list from .gif in dir

Post by SpeakEasy »

>Individual images in an ImageList control do not have a Tag

Erm ... are you quite sure?

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

Re: fill image list from .gif in dir

Post by HansV »

No. It turns out they do have a tag. Sorry for the misinformation.

Me.ImageList1.ListImages.Add(Picture:=LoadPicture(strPath & strFile)).Tag = "Italy"
Best wishes,
Hans