【问题标题】:Accessing resources like array's elements访问诸如数组元素之类的资源
【发布时间】:2014-05-05 08:36:28
【问题描述】:

我有两个资源:1.jpg2.jpg。我可以像这样访问它们:

pictureBox1.Image = Properties.Resources.Computer1;
pictureBox1.Image = Properties.Resources.Computer2;

但是如果我想通过索引来访问它呢:

pictureBox1.Image = Properties.Resources.Computer[0];

我该怎么做?

【问题讨论】:

    标签: c# visual-studio resources windows-forms-designer


    【解决方案1】:

    您已经使用 index.html 命名了图像名称。 因此,您可以访问这些文件,如下所示,

    for(int i = 0; i < 2; i++) 
    {
    
      pictureBox1.Image = (Image)Properties.Resources.ResourceManager.GetObject("Computer" + i);
    
    }
    

    而且,我想推荐阅读以下文章。

    Load image from resources

    C# Resource Array

    【讨论】:

      猜你喜欢
      • 2013-02-11
      • 2021-10-31
      • 2013-05-23
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 1970-01-01
      相关资源
      最近更新 更多