日期:2014-05-18 浏览次数:20977 次
//拉一个Timer控件到窗体,一个Label,两个Button Random rnd=new Random(unchecked((int)DateTime.Now.Ticks));//声明一个全局变量 private void timer1_Tick(object sender, System.EventArgs e)//添加Timer的Tick事件 { this.label1.Text=rnd.Next(1,39).ToString(); } private void btnStart_Click(object sender, System.EventArgs e)//开始按钮的Click事件 { this.timer1.Start(); } private void btnEnd_Click(object sender, System.EventArgs e)//结束按钮的Click事件 { this.timer1.Stop(); }
------解决方案--------------------
这个要用到线程,因为你要在数字滚动的时候还可以点击按钮..
------解决方案--------------------
Random random = new Random();
List<int> old = new List<int>();
for (int i = 0; i < 35; i++)
{
int r = random.Next(1, 35);
while (old.Contains(r))
{
r = random.Next(1, 35);
}
old.Add(r);
lable.Text = r.ToString();
Thread.Sleep(1000);
}
old.Clear();
------解决方案--------------------
很久很久以前做的一个双色球,拿出主要的给你看看
private void timer2_Tick(object sender, System.EventArgs e) { Random a=new Random(); int i1=a.Next(1,33); if(i1<10) { this.textBox1.Text="0"+i1.ToString(); } else { this.textBox1.Text=i1.ToString(); } int i2=a.Next(1,33); if(i2<10) { this.textBox2.Text="0"+i2.ToString(); } else { this.textBox2.Text=i2.ToString(); } int i3=a.Next(1,33); if(i3<10) { this.textBox3.Text="0"+i3.ToString(); } else { this.textBox3.Text=i3.ToString(); } int i4=a.Next(1,33); if(i4<10) { this.textBox4.Text=")"+i4.ToString(); } else { this.textBox4.Text=i4.ToString(); } int i5=a.Next(1,33); if(i5<10) { this.textBox5.Text="0"+i5.ToString(); } else { this.textBox5.Text=i5.ToString(); } int i6=a.Next(1,33); if(i6<10) { this.textBox6.Text="0"+i6.ToString(); } else { this.textBox6.Text=i6.ToString(); } int i7=a.Next(1,16); if(i7<10) { this.textBox7.Text="0"+i7.ToString(); } else { this.textBox7.Text=i7.ToString(); } }
------解决方案--------------------
private void button1_Click(object sender, EventArgs e) { timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { Random r = new Random(); int t = r.Next(0, 100); this.label1.Text = t.ToString(); } private void button2_Click(object sender, EventArgs e)