0

I have a VB.NET program with lots of embedded resources which are images. Is there a way to get all the resources in an array so I can acces them in a for loop?

I currently have to do it this way:

 images(1) = My.Resources.image1
 images(2) = My.Resources.image2
 '...
 images(80) = My.Resources.image80
1

1 Answer 1

2

Something like this perhaps:

Dim ResourceSet As Resources.ResourceSet = My.Resources.ResourceManager.GetResourceSet(Globalization.CultureInfo.CurrentCulture, True, True)
For Each Dict As DictionaryEntry In ResourceSet.OfType(Of Object)()
    If TypeOf (Dict.Value) Is Drawing.Image Then
        Debug.WriteLine(Dict.Key) 'outputting resource name
       (Do stuff here)
    End If
Next

It appears that the key is the name of the resource.

Sign up to request clarification or add additional context in comments.

2 Comments

it says: System.ArgumentNullException was unhandled Message=Value cannot be null. Parameter name: source
Sorry, edited above after actually testing it. There has to be a better way than that OfType(of Object) but I can't seem to see it. Also, I had to change the parameters in the GetResourceSet based on the application I tested this in... so you may need to adjust those. msdn.microsoft.com/en-US/library/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.