实例介绍
【实例简介】
【实例截图】
【核心代码】
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;
namespace WindowsForms
{
public partial class Chance : Form
{
public int 奖品1概率 = 25;
public int 奖品2概率 = 100;
public int 奖品3概率 = 100;
public int 奖品4概率 = 100;
public int 奖品5概率 = 100;
public int 奖品6概率 = 100;
public int 奖品7概率 = 100;
public int 未中奖概率 = 100;
public int G;
public double G1;
public double G2;
public double G3;
public double G4;
public double G5;
public double G6;
public double G7;
public double G8;
Thread 更新线程 = null;
SynchronizationContext 更新线程使者 = null;
int 暂停 = 0;
int 异常 = 0;
public Chance()
{
InitializeComponent();
更新线程使者 = SynchronizationContext.Current;
textBox1.Text = 奖品1概率.ToString();
textBox2.Text = 奖品2概率.ToString();
textBox3.Text = 奖品3概率.ToString();
textBox4.Text = 奖品4概率.ToString();
textBox5.Text = 奖品5概率.ToString();
textBox6.Text = 奖品6概率.ToString();
textBox7.Text = 奖品7概率.ToString();
textBox8.Text = 未中奖概率.ToString();
}
private void Chance_Load(object sender, EventArgs e)
{
概率计算();
概率写入();
更新Start();
}
public void 更新Start() //执行更新线程---线程2
{
更新线程 = new Thread(更新线程Do);
更新线程.Start();
}
public void 更新线程Do()
{
while (true)
{
bool T1 = double.TryParse(textBox1.Text, out double X1);
bool T2 = double.TryParse(textBox2.Text, out double X2);
bool T3 = double.TryParse(textBox3.Text, out double X3);
bool T4 = double.TryParse(textBox4.Text, out double X4);
bool T5 = double.TryParse(textBox5.Text, out double X5);
bool T6 = double.TryParse(textBox6.Text, out double X6);
bool T7 = double.TryParse(textBox7.Text, out double X7);
bool T8 = double.TryParse(textBox8.Text, out double X8);
if (T1 == true && T2 == true && T3 == true && T4 == true && T5 == true && T6 == true && T7 == true && T8 == true)
{
暂停 = 0;
异常 = 0;
}
if (暂停 == 1)
{
continue;
}
Thread.Sleep(100);
int 更新 = 0;
更新线程使者.Post(更新线程使者Do, 更新);
}
}
public void 更新线程使者Do(object 更新)
{
G = 奖品1概率 奖品2概率 奖品3概率 奖品4概率 奖品5概率 奖品6概率 奖品7概率 未中奖概率;
强制转换();
概率计算();
概率写入();
}
void 概率计算()
{
G1 = double.Parse(textBox1.Text) * 1.0 / G;
G2 = double.Parse(textBox2.Text) * 1.0 / G;
G3 = double.Parse(textBox3.Text) * 1.0 / G;
G4 = double.Parse(textBox4.Text) * 1.0 / G;
G5 = double.Parse(textBox5.Text) * 1.0 / G;
G6 = double.Parse(textBox6.Text) * 1.0 / G;
G7 = double.Parse(textBox7.Text) * 1.0 / G;
G8 = double.Parse(textBox8.Text) * 1.0 / G;
}
public void 概率写入()
{
textBoxG1.Text = G1.ToString() "%";
textBoxG2.Text = G2.ToString() "%";
textBoxG3.Text = G3.ToString() "%";
textBoxG4.Text = G4.ToString() "%";
textBoxG5.Text = G5.ToString() "%";
textBoxG6.Text = G6.ToString() "%";
textBoxG7.Text = G7.ToString() "%";
textBoxG8.Text = G8.ToString() "%";
}
void 强制转换()
{
bool T1 = double.TryParse(textBox1.Text, out double X1);
bool T2 = double.TryParse(textBox2.Text, out double X2);
bool T3 = double.TryParse(textBox3.Text, out double X3);
bool T4 = double.TryParse(textBox4.Text, out double X4);
bool T5 = double.TryParse(textBox5.Text, out double X5);
bool T6 = double.TryParse(textBox6.Text, out double X6);
bool T7 = double.TryParse(textBox7.Text, out double X7);
bool T8 = double.TryParse(textBox8.Text, out double X8);
if (T1 == true)
{
textBox1.BackColor = Color.GreenYellow;
暂停 = 0;
奖品1概率 = int.Parse(textBox1.Text);
}
if (T2 == true)
{
textBox2.BackColor = Color.GreenYellow;
暂停 = 0;
奖品2概率 = int.Parse(textBox2.Text);
}
if (T3 == true)
{
textBox3.BackColor = Color.GreenYellow;
暂停 = 0;
奖品3概率 = int.Parse(textBox3.Text);
}
if (T4 == true)
{
textBox4.BackColor = Color.GreenYellow;
暂停 = 0;
奖品4概率 = int.Parse(textBox4.Text);
}
if (T5 == true)
{
textBox5.BackColor = Color.GreenYellow;
暂停 = 0;
奖品5概率 = int.Parse(textBox5.Text);
}
if (T6 == true)
{
textBox6.BackColor = Color.GreenYellow;
暂停 = 0;
奖品6概率 = int.Parse(textBox6.Text);
}
if (T7 == true)
{
textBox7.BackColor = Color.GreenYellow;
暂停 = 0;
奖品7概率 = int.Parse(textBox7.Text);
}
if (T8 == true)
{
textBox8.BackColor = Color.GreenYellow;
暂停 = 0;
奖品1概率 = int.Parse(textBox8.Text);
}
if (T1 == false || textBox1.Text == "")
{
textBox1.BackColor = Color.Red;
异常 ;
if (异常 == 1)
{ MessageBox.Show("此值输入无效!"); }
暂停 = 1;
}
if (T2 == false || textBox2.Text == "")
{
textBox2.BackColor = Color.Red;
异常 ;
if (异常 == 1)
{ MessageBox.Show("此值输入无效!"); }
暂停 = 1;
}
if (T3 == false || textBox3.Text == "")
{
textBox3.BackColor = Color.Red;
异常 ;
if (异常 == 1)
{ MessageBox.Show("此值输入无效!"); }
暂停 = 1;
}
if (T4 == false || textBox4.Text == "")
{
textBox4.BackColor = Color.Red;
异常 ;
if (异常 == 1)
{ MessageBox.Show("此值输入无效!"); }
暂停 = 1;
}
if (T5 == false || textBox5.Text == "")
{
textBox5.BackColor = Color.Red;
异常 ;
if (异常 == 1)
{ MessageBox.Show("此值输入无效!"); }
暂停 = 1;
}
if (T6 == false || textBox6.Text == "")
{
textBox6.BackColor = Color.Red;
异常 ;
if (异常 == 1)
{ MessageBox.Show("此值输入无效!"); }
暂停 = 1;
}
if (T7 == false||textBox7.Text == "")
{
textBox7.BackColor = Color.Red;
异常 ;
if (异常 == 1)
{ MessageBox.Show("此值输入无效!"); }
暂停 = 1;
}
//this.数据一.判断数字();
if (T8 == false || textBox8.Text == "")
{
textBox8.BackColor = Color.Red;
异常 ;
if (异常 == 1)
{ MessageBox.Show("此值输入无效!"); }
暂停 = 1;
}
}
public void button_退出_Click(object sender, EventArgs e)
{
this.Hide();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
public void T9(string a)
{
textBox9.Text = a;
}
private void textBoxG7_TextChanged(object sender, EventArgs e)
{
}
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论