Search code examples
c#.netvb.netimagelist

How do you add image file to a image list in code?


I have an image list and would like to add a directory of images to the image list in my code. How would I do this? When I run the code:

'Load all of the items from the imagelist
For Each path As String In Directory.GetFiles("Images\LanguageIcons\")
     imlLanguagesIcons.Images.Add(Image.FromFile(path))
Next

I get an out of memory exception. Currently there is only 14 images so there really shouldn't be a problem. Any Help?


Solution

  • Like this

    imageList.Images.Add(someImage);
    

    Where someImage is an Image variable.

    EDIT: Like this:

    For Each path As String In Directory.GetFiles("Images\LanguageIcons")
        imageList.Images.Add(Image.FromFile(path))
    Next