基于C#设计一个双色球选号工具
作者:THIM 时间:2021-10-07 20:39:57
窗体展示
开始后展示
结束摇色展示
代码
导入的命名空间
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());
}
来源:https://blog.csdn.net/qq_50767141/article/details/123934475
标签:C#,双色球
0
投稿
猜你喜欢
mybatis的大于小于号转义符号一览
2023-05-31 07:23:03
JavaWeb使用POI操作Excel文件实例
2022-06-12 18:19:30
java读取XML文件的四种方法总结(必看篇)
2023-03-22 23:12:58
Java Swing实现扫雷源码
2023-11-10 08:16:20
C#图片按比例缩放的实现代码
2022-12-19 03:58:16
关于在IDEA中SpringBoot项目中activiti工作流的使用详解
2022-12-11 01:24:28
读取Java文件到byte数组的三种方法(总结)
2023-08-01 17:19:39
Android编程之高效开发App的10个建议
2021-08-28 15:55:46
SpringBoot整合SpringSecurity实现JWT认证的项目实践
2022-06-23 22:09:09
maven的pom.xml中profiles的作用详解
2022-07-03 20:40:54
C#集合之栈的用法
2022-09-09 17:01:49
一篇文章带你搞定JAVA注解
2023-03-15 05:22:23
Java输入/输出流体系详解
2023-03-01 06:37:00
IDEA自定义常用代码块及自定义快捷摸板
2022-01-13 18:54:22
详解android 中animation-list 动画的应用
2022-09-13 18:28:31
教你C#将CSV转为Excel的实现方法
2021-09-18 00:42:03
Android实现支持所有View的通用的下拉刷新控件
2022-07-29 10:40:36
Java二分查找算法实现代码实例
2023-08-24 05:34:23
Unity实现答题系统的示例代码
2022-05-09 18:31:00
C# lambda表达式原理定义及实例详解
2021-07-26 21:44:44