您好,登錄后才能下訂單哦!
這篇文章主要介紹了基于C#怎么設計一個雙色球選號工具的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇基于C#怎么設計一個雙色球選號工具文章都會有所收獲,下面我們一起來看看吧。
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;
private string[] red = { "01","02","03","04","05","06", "07","08","09","10","11","12","13","14","15","16","17"}; private string[] blue = {"01","02","03","04","05","06", "07","08","09","10" }; private bool begin = true;
private void Form1_Load(object sender, EventArgs e) { foreach(var item in groupBox1.Controls) { if(item is Label) { ((Label)item).Text = "00"; } } button2.Enabled = false; }
private void button1_Click(object sender, EventArgs e) { button1.Text = "已經開始"; button1.Enabled = false; button2.Enabled = true; begin = true; TaskFactory f = new TaskFactory(); List<Task> list = new List<Task>(); foreach(var item in groupBox1.Controls) { if(item is Label) { ((Label)item).Text = "00"; } } foreach( var item in groupBox1.Controls) { if(item is Label) { Label lbl = item as Label; list.Add(f.StartNew(() => { Random r = new Random(); while (begin) { string txt = ""; if (lbl.Name.Contains("Red")) { lock (obj) { txt = red[r.Next(0, 17)]; Update(lbl, txt); } } else { txt = blue[r.Next(0, 10)]; Update(lbl, txt); } Thread.Sleep(10); } })); } } f.ContinueWhenAll(list.ToArray(), tList => this.ShowResult()); }
private void Update(Label label , string text) { this.Invoke(new Action(() => { label.Text = text; })); }
private void button2_Click(object sender, EventArgs e) { button1.Text = "開始"; button1.Enabled = true; button2.Enabled = false; begin = false; }
private void ShowResult() { StringBuilder s = new StringBuilder(); s.Append(lblRed1.Text + " "); s.Append(lblRed2.Text + " "); s.Append(lblRed3.Text + " "); s.Append(lblRed4.Text + " "); s.Append(lblRed5.Text + " "); s.Append(lblRed6.Text + " \n"); s.Append($"blueBob: {lblBlue.Text}"); MessageBox.Show(s.ToString()); }
關于“基于C#怎么設計一個雙色球選號工具”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“基于C#怎么設計一個雙色球選號工具”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。