基本信息
源码名称:C# WindowsForms简单程序; 生成一组双色球随机号码
源码大小:1.36M
文件格式:.rar
开发语言:C#
更新时间:2019-09-05
   源码介绍

C# WindowsForms简单程序;  生成一组双色球随机号码。

入门级窗口程序,告别枯燥的DOS界面。

using System;
using System.Windows.Forms;

namespace 双色球WindowsForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int[] red = new int[6];
            Random s = new Random();
            //从1~33中生成6个不重复的随机数红球;
            for (int i = 0; i < 6; i  )
            {
                int a = s.Next(1, 34), j;
                for (j = 0; j < i; j  )
                {
                    if (a == red[j])
                    {
                        i--;
                        break;
                    }
                }
                red[j] = a;
            }
            //为生成的红球按从小到大排序;
            for (int i = 0; i < 6; i  )
            {
                for (int j = i; j < 5; j  )
                {
                    if (red[i] > red[j   1])
                    {
                        int 中间变量 = red[i];
                        red[i] = red[j   1];
                        red[j   1] = 中间变量;
                    }
                }
            }


            textBox1.Text = red[0].ToString();
            textBox2.Text = red[1].ToString();
            textBox3.Text = red[2].ToString();
            textBox4.Text = red[3].ToString();
            textBox5.Text = red[4].ToString();
            textBox6.Text = red[5].ToString();


            //从1~16中生成1个随机数篮球;
            int blue = s.Next(1, 17);
            textBox7.Text = blue.ToString();
        }

        //清空内容;
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
        }
    }
}