|
Using timer is very simple, put the numbers you want to draw into the numbers array.
private string [] numbers = null;
The
private void btnStart_Click (object sender, System.EventArgs e)
{
this.timer1.Interval = 100;
this.timer1.Start ();
this.btnStart.Enabled = false;
this.btnStop.Enabled = true;
}
private void Form1_Load (object sender, System.EventArgs e)
{
numbers = new string [] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
this.timer1.Tick + = new System.EventHandler (this.timer1_Tick);
this.btnStart.Enabled = true;
this.btnStop.Enabled = false;
}
private void timer1_Tick (object sender, EventArgs e)
{
this.txtNumber.Text = GetRandomNumber (this.numbers);
}
private string GetRandomNumber (string [] numbers)
{
if (numbers == null || numbers.Length == 0)
return "";
Random rdm = new Random (unchecked ((int) DateTime.Now.Ticks));
int index = rdm.Next (0, numbers.Length-1);
return numbers [index];
}
private void btnStop_Click (object sender, System.EventArgs e)
{
this.timer1.Stop ();
this.btnStart.Enabled = true;
this.btnStop.Enabled = false;
} |
|