返回首页
当前位置: 主页 > 编程语言 > C#教程 >

C#实现抽奖机源码-winform程序

时间:2016-05-13 12:07来源:电脑教程学习网 www.etwiki.cn 编辑:admin

组件清单:

[label1 label2 label3 button1]

代码清单:

C#实现抽奖机源码-winform程序
 

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

namespace C#实现抽奖机源码-dengzhenzhen.com
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Thread th;
bool b = false;

private void button1_Click(object sender, EventArgs e)
{
if (b==false)
{

b = true;
th = new Thread(GameStart);
th.IsBackground = true;
th.Start();
button1.Text = "暂停";


}
else
{

button1.Text = "开始";
b = false;

}



}


public void GameStart()
{
Random r = new Random();
while (b)
{
try
{
label1.Text = r.Next(0, 10).ToString();
label2.Text = r.Next(0, 10).ToString();
label3.Text = r.Next(0, 10).ToString();

}
catch
{

}
}
}

private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (th != null)
{
th.Abort();
}
}
}
}

------分隔线----------------------------
标签(Tag):c# c#技巧 c#实例教程 c#源代码 c#基础教程
------分隔线----------------------------
推荐内容
猜你感兴趣