2

In a C# Winforms app, how can I access Resources via string? For example I know I can do Properties.Resources.MyImage however, I won't know which image I need until runtime. With a string containing "MyImage", how can I access Properties.Resources.MyImage? Ideally, I was hoping for something easy such as Properties.Resources["MyImage"], but with some searching around haven't been able to find a quick solution to this.

Any help is appreciated.

1
  • 1
    Get an object from resources and typecast that to a bitmap Bitmap myImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("myImage"); Commented May 22, 2017 at 5:10

1 Answer 1

7

You can use ResourceManager.GetObject() like this:

string resourceName = "MyImageNameHere";
Bitmap bmp = (Bitmap)Properties.Resources.ResourceManager.GetObject(resourceName);
pictureBox1.Image = bmp;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.