这篇文章主要为大家详细介绍了如何利用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#双色球的资料请关注得得之家其它相关文章!
沃梦达教程
本文标题为:基于C#设计一个双色球选号工具
基础教程推荐
猜你喜欢
- 一个读写csv文件的C#类 2022-11-06
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- unity实现动态排行榜 2023-04-27
- C#类和结构详解 2023-05-30
- winform把Office转成PDF文件 2023-06-14
- ZooKeeper的安装及部署教程 2023-01-22
- C#控制台实现飞行棋小游戏 2023-04-22
- C# windows语音识别与朗读实例 2023-04-27
- C# 调用WebService的方法 2023-03-09
- C# List实现行转列的通用方案 2022-11-02