Hi!

I'm writing a program about trying different images in picturebox, but the image must correspond to the text. Plus it must come from "Resources" folder of the project.

this is what i want to do if the text "apple" displays to the screen then the image with a filename "apple" would also display in the picturebox..

I can do it in "if-else" like this

string word="apple";
if(word==apple)
pictureBox1.Image=  WindowsFormsApplication4.Properties.Resources.apple;

but What if I have a thousand images, I still think there's an easy way for this,..


i'm trying this one,,

string word=label1.Text;//label1.text changes from time to time
pictureBox1.Image= WindowsFormsApplication4.Properties.Resources.word;

but I know "word" is string....It's not possible...I cannot append string to the syntax....


Help please??

Recommended Answers

All 4 Replies

Perhaps you could consider a switch statement.
look here: http://msdn.microsoft.com/en-us/library/06tc147t.aspx

If-else and switch case is applicable..but the condition is what if I have for example a hundred images.. I'll do one hundred ifs' or cases' in switch element??!

I believe there's an easy way for this.. I think so..Still figuring it out...

Perhaps you could consider a switch statement.
look here: http://msdn.microsoft.com/en-us/library/06tc147t.aspx

If-else and switch case is applicable..but the condition is what if I have for example a hundred images.. I'll do one hundred ifs' or cases' in switch element??!

I believe there's an easy way for this.. I think so..Still figuring it out... Thanks for the suggestion anyway.. appreciated it...:)

Well, I think this article will be helpfull.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.