vb.net 如何从资源文件填充 ImageList

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12980861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 15:59:23  来源:igfitidea点击:

How to populate an ImageList from a Resource File

vb.netimagelist

提问by Qu1nncunxIV

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.

只是想知道是否有办法从资源文件中填充 ImageList。我在网上环顾四周,但一切似乎都是从 2003/2005 年开始的。

Any advice would be appreciated thanks in advance.

任何建议将不胜感激,提前致谢。

回答by noctural

Here is an example of reading all images in a resource into an ImageList.

这是将资源中的所有图像读入 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);
      }
   }
}

回答by Ravindra Bagale

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");

回答by Pakk

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?

你试过循环这个吗?我知道这是一篇旧帖子,但你为什么要输入 100 行相同的代码 +- 1 个变量?