TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
momo akhouri
NA
2
3.8k
How do I compare user input to an image in Image[ ]
Aug 30 2012 8:33 AM
Hey!
I'm having a bit of trouble in making a "guess the flag" game in C#.
I have managed to create a picturebox in which random pictures (national flags) are displayed when a button is clicked.
However, I need to be able to make it so that the user can guess which country the flag belongs to, e.g. if the american flag appears, then the user can input "america" in a textbox and the progam should determine whether it is the correct answer or not.
Essentially, my question is:
How do I compare textbox.text with the image that appears by the Random() class?
My code:
public partial class Form1 : Form
{
Random r = new Random();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Array of images
Image[] images = new Image[3];
images[0] = Image.FromFile(@"C:\Users\Momo\Desktop\flags 1\india.png");
images[1] = Image.FromFile(@"C:\Users\Momo\Desktop\flags 1\australia.png");
images[2] = Image.FromFile(@"C:\Users\Momo\Desktop\flags 1\america.png");
int random = r.Next(0, 3);
//set picturebox to random
pictureBox1.Image = images[random];
}
Thank you
Reply
Answers (
1
)
Scheduler
app.config file