How to populate an ImageList from a Resource File

心已入冬 提交于 2019-12-21 23:43:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!