So, I am trying to make the MasterMind program as an exercise.
- Field of 40 picture boxes (line of 4, 10 lines)
- 6 buttons (red, green, orange, yellow, blue, purple)
When I click one of these buttons (allows you to accept red), then the image window turns red.
My question is, how can I iterate over all these image fields?
I can make it work, but only if I write:
And that doesn’t mean that we cannot write it, I will have countless lines that contain basically the same.
private void picRood_Click(object sender, EventArgs e)
{
UpdateDisplay();
pb1.BackColor = System.Drawing.Color.Red;
}
Press the red button → the first screenshot will turn red
Press the blue button → the second screen will turn blue
Press the orange button → the third picture will be orange
And so on ...
I had a previous similar program that simulates a traffic light, there I can assign a value for each color (red 0, orange 1, green 2).
Something similar is needed or exactly how I address all these boxes with pictures and make them appropriate to the button.
Regards.
source
share