JedNebula
asked on
Iterate through My.Resources
I have done a few Google searches and not found anything so I'm thinking it can't be done, but I'm wondering if there is a way to loop (or iterate) through the My.Resources so I can do something with each icon/image for example.
Something like this:
For each ico as Icon in My.Resources
.....
Next ico
Something like this:
For each ico as Icon in My.Resources
.....
Next ico
If you're OK in C#, try reading this article that covers the exact question you ask and many more things regarding resources.
Here's a little simplified VB variant of the code provided in the article.
You should add multiline TextBox txtInfo for this to work.
You should add multiline TextBox txtInfo for this to work.
Public Class Form1
Dim pics As System.Collections.ArrayList = New ArrayList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim imgStream As IO.Stream
Dim bmp As Bitmap
Dim a As Reflection.Assembly
a = Reflection.Assembly.GetExecutingAssembly()
Dim ResNames As String()
ResNames = a.GetManifestResourceNames()
txtInfo.Clear()
txtInfo.Text += String.Format("Found {0} resources\r\n", ResNames.Length)
txtInfo.Text += "----------\r\n"
For Each s As String In ResNames
txtInfo.Text += s + "\r\n"
If s.EndsWith(".bmp") Then
' attach to stream to the resource in the manifest
imgStream = a.GetManifestResourceStream(s)
'create a new bitmap from this stream and
'add it to the arraylist
bmp = Bitmap.FromStream(imgStream)
pics.Add(bmp)
imgStream.Close()
End If
Next
txtInfo.Text += "----------\r\n"
txtInfo.Text += String.Format("Found {0} Bitmaps\r\n", pics.Count)
End Sub
End Class
ASKER
Thanks guys.
I'm finding that it's not picking up the images in my.Resources. The images are Embedded in .resx and they are ico and .bmp formats. (see image)
Here is the result from the textbox:
Found 22 resources\r\n----------\r\ nEcho.Reso urces.reso urces\r\nE cho.frmEdi tServer.re sources\r\ nEcho.frmC hangeLog.r esources\r \nEcho.frm TaskProgre ss.resourc es\r\nEcho .frmOption s.resource s\r\nEcho. frmMDIStat us.resourc es\r\nEcho .frmHASPEr ror.resour ces\r\nEch o.frmConne ct.resourc es\r\nEcho .frmMain.r esources\r \nEcho.frm Task.resou rces\r\nEc ho.exe.lic enses\r\nE cho.frmTra y.resource s\r\nEcho. frmLogon.r esources\r \nEcho.frm ExceptionL og.resourc es\r\nEcho .ServerDet ailsContro l.resource s\r\nEcho. TasksActio nControl.r esources\r \nEcho.frm ExceptionH andler.res ources\r\n Echo.frmSe curity.res ources\r\n Echo.frmEx pBar.resou rces\r\nEc ho.frmEdit Servers.re sources\r\ nEcho.frmT est.resour ces\r\nEch o.frmSplas h.resource s\r\n----- -----\r\nF ound 0 Bitmaps\r\n
experts-exchange.jpg
I'm finding that it's not picking up the images in my.Resources. The images are Embedded in .resx and they are ico and .bmp formats. (see image)
Here is the result from the textbox:
Found 22 resources\r\n----------\r\
experts-exchange.jpg
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.