基本信息
源码名称:C# 摇奖机Demo(入门级示例)
源码大小:2.17M
文件格式:.rar
开发语言:C#
更新时间:2020-02-25
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace 摇奖机
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;//关闭跨线程检测,底下是死循环,两个线程会抛异常
        }
        bool flag = false;
        string str = string.Empty;
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt16(pictureBox1.Tag) == 0)//判断开关状态,为0则打开
            {
                pictureBox1.Image = Properties.Resources.switch_on_normal;
                pictureBox1.Tag = 1;
                flag = true;
                Thread th = new Thread(start);//新建线程,用于运行方法start
                th.IsBackground = true;
                th.Start();//开始线程
            }
            else 
            {
                pictureBox1.Image = Properties.Resources.switch_off_clicked;//关闭开关
                pictureBox1.Tag = 0;
                flag = false;
               
                if (label3.Text == label2.Text && label2.Text == label1.Text)//下为中奖号码判断
                {
                    textBox1.Text = string.Format("恭喜你中到一等奖{0},么么哒,努力写代码噢", str);
                }
                else if (label3.Text == label2.Text || label2.Text == label1.Text || label1.Text == label3.Text)
                {
                    textBox1.Text = string.Format("恭喜你中到二等奖{0},再接再厉", str);
                }
                else
                {
                    textBox1.Text = string.Format("很抱歉,你没有中奖{0},换个抽奖姿势把", str);
                }
            }
        }
        private void start()
        {
            Random r = new Random();//生成3个随机数
            while (flag)
            {
                label3.Text = r.Next(0, 10).ToString();
                Thread.Sleep(100);//数字变化太快,所以挂起0.1s线程;
                label2.Text = r.Next(0, 10).ToString();
                Thread.Sleep(100);
                label1.Text = r.Next(0, 10).ToString();
                Thread.Sleep(100);
                 

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Clear();//清空文本
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label6.Text = label6.Text.Substring(1)   label6.Text.Substring(0, 1);//提示信息的播报
        }
    }
}