Good night friends.
I have 20 checkbox and 20 textbox. The idea is that when the user checks a checkbox, I need to put it in the textbox
corresponding the result of a routine. That is, if the user clicks on checkbox 2, I need to put the result
in textbox2. If I check checkbox 10, I need to put the result in textBox10.
I'm doing this:
int numjogo;
if (checkBox1.Checked == true)
{
numjogo = 1;
textBox1.Text = subverificaacertos(numjogo).ToString();
if (Convert.ToInt32(textBox1.Text) >= 11)
{
textBox1.BackColor = Color.Blue;
textBox1.ForeColor = Color.Yellow;
cp.Add(numjogo);
tempremio = 1;
}
}
if (checkBox2.Checked == true)
{
numjogo = 2;
textBox2.Text = subverificaacertos(numjogo).ToString();
if (Convert.ToInt32(textBox2.Text) >= 11)
{
textBox2.BackColor = Color.Blue;
textBox2.ForeColor = Color.Yellow;
cp.Add(numjogo);
tempremio = 1;
}
}
I do this for each checkbox, which is 20.
I was trying to make the code below to replace the 20 codes above.
int numjogo;
foreach (Control c in panel16.Controls)
{
if (c is CheckBox && (c as CheckBox).Checked)
{
numjogo = Convert.ToInt32(c.Text);
textBox?.Text = subverificaacertos(numjogo).ToString();
if (Convert.ToInt32(textBox?.Text) >= 11)
{
textBox?.BackColor = Color.Blue;
textBox?.ForeColor = Color.Yellow;
cp.Add(numjogo);
tempremio = 1;
}
}
}
How to replace the textBox above with ? by the textbox corresponding to the clickbox clicked?
I thought of creating a list with the names of the 20 textBox. But I don't even know if that is possible.
And I also confess that I wouldn't know how to do it.
Thank you.