这篇文章主要介绍了基于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#怎么设计一个双色球选号工具”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。