返回首頁
當前位置: 主頁 > 編程語言 > C#教程 >

C#實現抽獎機源碼-winform程序

時間:2016-05-13 12:07來源:電腦教程學習網 www.aedwey.tw 編輯: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#基礎教程
------分隔線----------------------------
推薦內容
猜你感興趣
26选5中奖通告