Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically access images in a resource file?

I have 30 PNGs in a resource file and I would like to iterate around them inside a timer. This timer sets the form's background image to the next PNG in the sequence to produce a basic animation.

I can't find an easy way to enumerate the resource file and get at the actual images. I am also keen to keep the references to the images not fixed to their filenames so that updating the naming of the images within the Resource File would not require me to update this section of code.

Notes:

  • The images inside the resource file are named in sequence ('image001.png', 'image002.png', ...).
  • This resource file is used exclusively to store these images.
like image 598
InvertedAcceleration Avatar asked Oct 14 '22 10:10

InvertedAcceleration


1 Answers

    private void Form1_Load(object sender, EventArgs e)
    {
        var list = WindowsFormsApplication1.Properties.Resources.ResourceManager.GetResourceSet(new System.Globalization.CultureInfo("en-us"), true, true);
        foreach (System.Collections.DictionaryEntry img in list)
        {
            System.Diagnostics.Debug.WriteLine(img.Key);
            //use img.Value to get the bitmap
        }

    }
like image 134
Fredou Avatar answered Oct 19 '22 07:10

Fredou