Get the App
SLTechnology News&Howtos  ›  Development  › 

How to design a two-color ball number selection tool based on C#

Shulou Source: shulou.com Published: 2022-06-01 01:22:20 10月05日 Update

This article mainly introduces the relevant knowledge of how to design a two-color ball number selection tool based on C#, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to design a two-color ball number selection tool based on C#. Let's take a look.

Form display

Show after start

End the rocking show.

Code imported namespace 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 Initialize private variables 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 Page initialization 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;} start button private void button1_Click (object sender, EventArgs e) {button1.Text = "already started"; button1.Enabled = false; button2.Enabled = true; begin = true; TaskFactory f = new TaskFactory () List list = new List (); 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 ()) } Digital update private void Update (Label label, string text) {this.Invoke (new Action () = > {label.Text = text;});} end button private void button2_Click (object sender, EventArgs e) {button1.Text = "start"; button1.Enabled = true Button2.Enabled = false; begin = false;} results show 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 ());} this article on" how to design a two-color ball number selection tool based on C # "ends here, thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to design a two-color ball number selection tool based on C#". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Two-color two-color ball tools number selection clips design knowledge content buttons articles code values variables easy to operate numbers articles easy to understand more see space Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia Shulou Tech Info Linux Microsoft