问题
Just wondering if there is a way to populate an ImageList from a Resource file. I have looked around on the web, but everything seems to have been from back in 2003/2005.
Any advice would be appreciated thanks in advance.
回答1:
Here is an example of reading all images in a resource into an ImageList.
var dynamicImageList = new ImageList();
var resourceSet = MyResourceClass.ResourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, false);
if (resourceSet != null)
{
foreach (DictionaryEntry entry in resourceSet)
{
var value = entry.Value as Bitmap; //only get images
if (value != null)
{
dynamicImageList.Images.Add((string) entry.Key, value);
}
}
}
回答2:
try this one
Private m_clsImageList as ImageList
Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs)
m_clsImageList = New ImageList()
m_clsImageList.Images.Add("add", My.Resources.add)
m_clsImageList.Images.Add("cut", My.Resources.cut)
End Sub
or
resources = new ResourceManager("Icons", assemby-containing-icons.resx);
imageList.Images.Add((Image)resources.GetObject("image-resource-name");
回答3:
Have you tried looping this? i know its an old post but why would you ever type out 100 lines of the same code +- 1 variable?
来源:https://stackoverflow.com/questions/12980861/how-to-populate-an-imagelist-from-a-resource-file