开始抽奖状态结束抽奖状态using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string[] participantList; bool isRunning false; private void button1_Click(object sender, EventArgs e) { if (!isRunning) { isRunning true; button1.Text 停止; } else { isRunning false; button1.Text 开始; } Thread thread new Thread(Run); thread.IsBackground true;//设置为后台线程 thread.Start(); } public void Run() { while (isRunning) { Random random new Random(); var index random.Next(0, participantList.Length - 1); label3.Text participantList[index]; } } private void Form1_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls false;//允许跨线程访问控件 participantList ConfigurationManager.AppSettings[participant].Split(,); } } }App.config?xml version1.0 encodingutf-8 ? configuration startup supportedRuntime versionv4.0 sku.NETFramework,Versionv4.8 / /startup appSettings !--参与人员名单-- add keyparticipant value张三,李四,王五/ /appSettings /configuration
抽奖小程式
发布时间:2026/6/24 3:17:36
开始抽奖状态结束抽奖状态using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string[] participantList; bool isRunning false; private void button1_Click(object sender, EventArgs e) { if (!isRunning) { isRunning true; button1.Text 停止; } else { isRunning false; button1.Text 开始; } Thread thread new Thread(Run); thread.IsBackground true;//设置为后台线程 thread.Start(); } public void Run() { while (isRunning) { Random random new Random(); var index random.Next(0, participantList.Length - 1); label3.Text participantList[index]; } } private void Form1_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls false;//允许跨线程访问控件 participantList ConfigurationManager.AppSettings[participant].Split(,); } } }App.config?xml version1.0 encodingutf-8 ? configuration startup supportedRuntime versionv4.0 sku.NETFramework,Versionv4.8 / /startup appSettings !--参与人员名单-- add keyparticipant value张三,李四,王五/ /appSettings /configuration