Search code examples
c#comboboxpictureboxresx

Is it possible to stream images from resources.resx?


I got about 100 images loaded in resx and was wondering if it was possible to add them to a stream and if it is how to do it.

My idea is this:

I got a combobox and from selecting an item from the combobox (same names as the images) it should load an image from resx to a picturebox.

I tried this example:

string SelectedComboboxItem = comboBox1.SelectedItem.ToString();
pictureBox1.Image = Properties.Resources.ResourceManager.GetObject(SelectedComboboxItem));

Which does not work since it can not convert object to system.drawing.image, same with .GetString & .GetType.

Or if there is any other way to do this then it would be very helpful!


Solution

  • You must cast object to your image type. Like so:

    pictureBox1.Image = (Image)Properties.Resources.ResourceManager.GetObject("RowNameInResourceFile"));
    

    For more examples look at this msdn page