namespace DoubleBall{ public partial class Form1 : Form { //创建选号器对象 private Selector numSelector = new Selector(); //每次得到的随机数 List<string> num = null; public Form1() { InitializeComponent(); this.btn_Stop.Enabled = false; } //启动选号 private void btn_Start_Click(object sender, EventArgs e) { this.btn_Start.Enabled = false; this.btn_Stop.Enabled = true; this.timer1.Start();//启动定时器 } private void timer1_Tick(object sender, EventArgs e) { //得到随机数 this.num = numSelector.CreateRandomNum(); //显示 this.label1.Text = num[0]; this.label2.Text = num[1]; this.label3.Text = num[2]; this.label4.Text = num[3]; this.label5.Text = num[4]; this.label6.Text = num[5]; this.label7.Text = num[6]; } //停止,并选择号码 private void btn_Stop_Click(object sender, EventArgs e) { this.btn_Start.Enabled = true; this.btn_Stop.Enabled = false; this.timer1.Stop(); //创建双色球对象,并且存储 Doubleball Doubleball_ok = new Doubleball(); Doubleball_ok.Numbers = this.num;//----注意该初始化方法!!!!!!! this.numSelector.Numbers1.Add(Doubleball_ok);//直接存储该对象 //显示号码 string num = string.Empty; foreach (string item in this.num) { num = item " "; } this.listBox1.Items.Add(num); label8.Text = this.listBox1.Items.Count.ToString(); } //清除选号 private void btn_Clear_Click(object sender, EventArgs e) { label8.Text = ""; this.numSelector.Numbers1.Clear(); this.listBox1.Items.Clear(); } }}
评论