程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> C#實現抽獎機源碼-winform程序

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

編輯:關於C#
 

組件清單:

[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();
}
}
}
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved