dimanche 9 avril 2017

c# select random from listbox and correlated item in second listbox

I have two sets of items in two listboxes. listBox1 has items listed out like:

red
yellow
blue

and listBox2 has items:

1
2
3

I also have two textboxes, textBox1 and textBox2. I have been successful in having a random item from listBox1 show up in textBox1, and I am now trying to check, with a button, if the text in textBox2, manually entered by the user, matched the corresponding items in listbox2.

So far, I have:

Random random = new Random();
int a; int n;
private void button1_Click(object sender, EventArgs e)
{
    n = listBox1.Items.Count;
    a = random.Next(n);
    textBox1.Text = listBox1.Items[a].ToString();
}

private void button2_Click(object sender, EventArgs e)
{
    //unsure
}

I am trying to have button2 check for whether or not textBox2 has typed into it the correctly corresponding item in listBox2 and display a message of some sort if it is correct. I'm a beginner at this, but I think I adequately grasp how to if/else the message if I can get the code leading up to it correct.

How do I check for such a link?




Aucun commentaire:

Enregistrer un commentaire