基于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#,双色球
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#使用委托实现的快速排序算法实例
2022-01-22 18:29:52
Java执行JS脚本工具
2022-04-07 08:00:16
![](https://img.aspxhome.com/file/2023/9/62159_0s.png)
C语言实现两个矩阵相乘
2023-07-22 12:41:20
![](https://img.aspxhome.com/file/2023/6/103076_0s.png)
Java编程实现打印螺旋矩阵实例代码
2021-10-16 19:15:14
![](https://img.aspxhome.com/file/2023/2/84202_0s.gif)
解读java try catch 异常后还会继续执行吗
2022-05-11 01:25:24
![](https://img.aspxhome.com/file/2023/7/66677_0s.png)
Spring Boot中@Conditional注解介绍
2022-03-03 15:23:37
![](https://img.aspxhome.com/file/2023/5/71225_0s.png)
java反射机制给实体类相同字段自动赋值实例
2023-11-25 19:52:29
Java 添加、读取和删除 Excel 批注的操作代码
2023-10-28 21:55:36
![](https://img.aspxhome.com/file/2023/5/81885_0s.png)
java8新特性将List中按指定属性排序过滤重复数据的方法
2023-06-16 17:57:42
![](https://img.aspxhome.com/file/2023/5/71935_0s.jpg)
springmvc与mybatis集成配置实例详解
2021-06-16 22:10:27
gradle使用maven-publish发布jar包上传到私有maven配置
2022-11-22 07:07:54
Java DatabaseMetaData用法案例详解
2023-08-18 19:08:42
浅谈C#中堆和栈的区别(附上图解)
2022-02-15 14:05:09
![](https://img.aspxhome.com/file/2023/9/80029_0s.gif)
Mybatis模糊查询及自动映射实现详解
2021-10-29 12:05:40
利用Spring boot+LogBack+MDC实现链路追踪
2023-10-03 16:02:53
解决eclipse启动tomcat时不能加载web项目的问题
2023-11-15 14:45:01
![](https://img.aspxhome.com/file/2023/3/92653_0s.png)
Javaweb中Request获取表单数据的四种方法详解
2023-10-07 03:07:02
![](https://img.aspxhome.com/file/2023/6/72606_0s.png)
SpringBoot解决Required String parameter xxx is not present问题
2021-08-08 12:53:15
详谈C++引用&和指针在作为形参时的区别
2023-12-13 16:50:49
SpringBoot接口调用之后报404问题的解决方案
2021-08-31 15:25:03
![](https://img.aspxhome.com/file/2023/4/86834_0s.png)