Guest Posted December 26, 2008 Share Posted December 26, 2008 (edited) I can change the image in a PictureBox to a picture stored in my resources by using the following... userAvatar.Image = new Bitmap(Properties.Resources.wario); However, i dont want to hardcode this "wario" image into the picturebox. I want the option to insert any image by means of a string... string myImage = "Properties.Resources.mario"; userAvatar.Image = new Bitmap(myImage); How can this be achieved. I have searched the internet but cant seem to find an answer. Thanks... and happy christmas guys :p Edited December 26, 2008 by Guest Link to comment Share on other sites More sharing options...
0 former1 Posted December 26, 2008 Share Posted December 26, 2008 never used C# but maybe you require "" or '' around the string name? Or even a $ before it? Just some guesses for you :p Link to comment Share on other sites More sharing options...
0 Kristian Posted December 26, 2008 Share Posted December 26, 2008 Haven't tried this out but you can test this: string myImage = "wario"; Bitmap picbox = new Bitmap(Properties.Resources.ResourceManager.GetString(myImage)); Link to comment Share on other sites More sharing options...
0 Guest Posted December 26, 2008 Share Posted December 26, 2008 Thanks Kristian... based my solution on your code... string myImage = "mario"; userAvatar.Image = (Image)Properties.Resources.ResourceManager.GetObject(myImage); :D Link to comment Share on other sites More sharing options...
Question
Guest
I can change the image in a PictureBox to a picture stored in my resources by using the following...
However, i dont want to hardcode this "wario" image into the picturebox. I want the option to insert any image by means of a string...
How can this be achieved. I have searched the internet but cant seem to find an answer.
Thanks... and happy christmas guys :p
Edited by GuestLink to comment
Share on other sites
3 answers to this question
Recommended Posts