using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { private Random random; public Form1() { InitializeComponent(); random = new Random(); } private void goCmd_Click(object sender, EventArgs e) { this.colours(); } private void colours() {
while (true) { int number = random.Next();
if ((number == 0) || (number == 5) || (number == 9)) { label1.BackColor = Color.Red; label2.BackColor = Color.Blue; label3.BackColor = Color.Yellow; label4.BackColor = Color.Green; label5.BackColor = Color.Chocolate; label6.BackColor = Color.PaleGreen; } if ((number == 2) || (number == 6) || (number == 4)) { label2.BackColor = Color.Red; label3.BackColor = Color.Blue; label4.BackColor = Color.Yellow; label5.BackColor = Color.Green; label6.BackColor = Color.Chocolate; label1.BackColor = Color.PaleGreen; } else { label3.BackColor = Color.Red; label4.BackColor = Color.Blue; label5.BackColor = Color.Yellow; label6.BackColor = Color.Green; label1.BackColor = Color.Chocolate; label2.BackColor = Color.PaleGreen; } }
}
} }
|
simple code to change the background colour of the labels in the form when the user presses the "go" command button, it just hang forever thou and doesn't even go into the loop, i dont need an exit condition either just a normal user close, can anyone suggest why this seemlingly easy code peice does not work?