新建一个 windows窗体应用程序 项目,在窗体上加一个TextBox控件(textBox1)和一个Button控件(button1),双击Button控件,在button1的点击事件的方法加入代码,如下,启动程序,点击按钮就可以看到随机生成的双色球号码。

 

  private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";

            //生成红色球号码
            List<int> _list;
            _list = new List<int>(33);
            for (int i = 1; i <34; i++)
            {
                _list.Add(i);
            }

            Random rd = new Random();
            int index;
            for (int i = 1; i < 7; i++)
            {
                index = rd.Next(_list.Count);
                textBox1.Text = textBox1.Text + _list[index].ToString();
                if (i < 6)
                    textBox1.Text = textBox1.Text + ", ";
                _list.RemoveAt(index);
            }


            //生成蓝色球号码
            Random rb = new Random();
            textBox1.Text = textBox1.Text + " + " + (rb.Next(16)+1).ToString();
            
        }

相关文章:

  • 2021-07-16
  • 2022-12-23
  • 2021-12-26
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2021-06-09
  • 2021-09-18
相关资源
相似解决方案