完整代码献上,欢迎纠错:
程序入口为WelcomeForm窗体。
WelcomeForm窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;//使用线程
using System.IO;//需要进行文件操作
namespace 原神UP角色抽卡模拟器
{
public partial class WelcomeForm : Form
{
public WelcomeForm()
{
InitializeComponent();
}
#region 变量的声明
int timerWelcomeCounter = 0;//timer的计数器
Thread threadCheckFiles = null;
const int N_Files = 83;//需要检查的文件总量的常数
string FileName_UP = "Cyno";//UP角色的名称,赛诺
string[] FileName_5 = new string[7] {
"Tighnari", //提纳里
"Dehya", //迪希雅
"Keqing", //刻晴
"Mona", //莫娜
"Qiqi", //七七
"Diluc", //迪卢克
"Jean"}; //琴
//奖池中5星非UP角色的名称,7项
string[] FileName_UP_4 = new string[3] {
"Xiangling", //香菱
"KukiShinobu", //久岐忍
"Kirara"}; //绮良良
//奖池中4星UP角色的名称,3项
string[] FileName_Role_4 = new string[30] {
"Freminet", //菲米尼
"Lynette", //琳妮特
"Kaveh", //卡维
"Mika", //米卡
"Yaoyao", //瑶瑶
"Faruzan", //珐露珊
"Lyala", //莱依拉
"Candace", //坎蒂丝
"Dori", //多莉
"Collei", //柯莱
"Yunjin", //云堇
"ShikanoinHeizou",//鹿野院平藏
"Kujosara", //九条裟罗
"Gorou", //五郎
"Sayu", //早柚
"Thoma", //托马
"Yanfei", //烟绯
"Rosaria", //罗莎莉亚
"Xinyan", //辛焱
"Sucrose", //砂糖
"Diona", //迪奥娜
"Chongyun", //重云
"Noelle", //诺艾尔
"Bennett", //班尼特
"Fischl", //菲谢尔
"Ningguang", //凝光
"Xingqiu", //行秋
"Beidou", //北斗
"Razor", //雷泽
"Barbara"}; //芭芭拉
//奖池中4星非UP角色的名称,30项
string[] FileName_Object_4 = new string[18] {
"Rust", //弓藏
"SacrificialBow", //祭礼弓
"TheStringless", //绝弦
"FavoniusWarbow", //西风猎弓
"EyeOfPerception", //昭心
"SacrificialFragments", //祭礼残章
"TheWidsith", //流浪乐章
"FavoniusCodex", //西风秘典
"FavoniusLance", //西风长枪
"Dragon'sBane", //匣里灭辰
"Rainslasher", //雨裁
"SacrificialGreatsword",//祭礼大剑
"TheBell", //钟剑
"FavoniusGreatsword", //西风大剑
"Lion'sRoar", //匣里龙吟
"SacrificialSword", //祭礼剑
"TheFlute", //笛剑
"FavoniusSword"}; //西风剑
//奖池4星武器,18项
string[] FileName_3 = new string[13] {
"Slingshot", //弹弓
"Sharpshooter'sOath", //神射手之誓
"RavenBow", //鸦羽弓
"EmeraldOrb", //翡玉法球
"ThrillingTalesOfDragonSlayers",//讨龙英杰谭
"MagicGuide", //魔导绪论
"BlackTassel", //黑缨枪
"DebateClub", //以理服人
"BloodtaintedGreatsword",//沐浴龙血的剑
"FerrousShadow", //铁影阔剑
"SkyriderSword", //飞天御剑
"HarbingerOfDawn", //黎明神剑
"CoolSteel"}; //冷刃
//3星物品,13项
public string BasePath = "bins\\sources\\", FileFormat = ".png";//相对地址为BasePath + [NAME] + FileFormat
bool FileError = false, OverChecked = false;
#endregion
private void CheckFiles()
{//检查文件完整性的线程
int Counter = 1;
Invoke(new Action(() =>
{
progressBarFile.Maximum = N_Files;
}));//跨线程操作
for (; Counter <= N_Files; Counter++)
methodCheckFiles(Counter);//逐个检查文件完整性
//OverChecked = true;
}
private void methodCheckFiles(int n)
{//检查文件完整性的方法
lock(this)//避免调用冲突
{
string temp = "";
if (n == 1) temp = FileName_UP;
else if (n >= 2 && n <= 8) temp = FileName_5[n - 2];
else if (n >= 9 && n <= 11) temp = FileName_UP_4[n - 9];
else if (n >= 12 && n <= 41) temp = FileName_Role_4[n - 12];
else if (n >= 42 && n <= 59) temp = FileName_Object_4[n - 42];
else if (n >= 60 && n <= 72) temp = FileName_3[n - 60];//以上将文件名(不含拓展名)记入temp中
else
{
BasePath = "bins\\";
FileFormat = ".mp4";
switch(n)
{
case 73: temp = "Prayer_1_5"; break;//单抽五星的视频
case 74: temp = "Prayer_1_4"; break;//单抽四星的视频
case 75: temp = "Prayer_1_3"; break;//单抽四星的视频
case 76: temp = "Prayer_10_5"; break;//十连抽有五星的视频
case 77: temp = "Prayer_10_4"; break;//十连抽无五星有四星的视频
case 78: temp = "IntertwinedFate"; FileFormat = ".png"; break; //纠缠之缘
case 79: temp = "MasterlessStardust"; FileFormat = ".png"; break; //无主的星尘
case 80: temp = "MasterlessStarglitter"; FileFormat = ".png"; break;//无主的星辉
case 81: temp = "Primogem"; FileFormat = ".png"; break; //原石
case 82: temp = "About_1"; FileFormat = ".png"; break;
case 83: temp = "About_2"; FileFormat = ".png"; break;
}
}
if (!File.Exists(BasePath + temp + FileFormat))
{
Invoke(new Action(() =>
{
progressBarFile.ForeColor = progressBarFile.BackColor = Color.Red;
this.TopMost = false;
progressBar.Enabled = false;
label_CheckInfo.Text = "File (" + BasePath + temp + FileFormat + ") is missing!";
label_CheckInfo.ForeColor = Color.Red;
}));//跨线程操作改变颜色
FileError = true;
DialogResult DR_FileError = MessageBox.Show("文件 " + BasePath + temp + FileFormat + "损坏,请重新下载软件。点击确定退出软件。", "文件丢失警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
threadCheckFiles.Interrupt();
if (DR_FileError == DialogResult.OK)
{
Application.Exit();
threadCheckFiles.Abort();//避免“对象未释放”的报错
}
}
else
{
if (!FileError)
{
Invoke(new Action(() =>
{
progressBarFile.Value++;
label_CheckInfo.Text = "Examing:" + BasePath + temp + FileFormat + "……";
Thread.Sleep(5);//用于增强观感
}));//跨线程操作改变进度条的进度
if (n >= 72)
{
OverChecked = true;
Invoke(new Action(() =>
{
label_CheckInfo.Text = "File check completed.";
label_CheckInfo.ForeColor = Color.Green;
}));//跨线程操作改变进度条的进度
}
}
}
}
}
private void WelcomeForm_Load(object sender, EventArgs e)
{
}
private void timerWelcome_Tick(object sender, EventArgs e)
{
timerWelcomeCounter++;
if (timerWelcomeCounter <= 5)
this.Opacity += 0.2;//透明显现
else if (timerWelcomeCounter <= 10)
{
if (timerWelcomeCounter==6)
{//此处添加检查文件完整性的线程
threadCheckFiles = new Thread(new ThreadStart(CheckFiles));
threadCheckFiles.Start();//定义并启动线程
}
timerWelcome.Interval = 200;//调整计时器的触发时间间隔
if (progressBar.Enabled) progressBar.Value += 20;
}
else
{
if ((!FileError) && OverChecked)
{
MainForm MF = new MainForm();
MF.Show();
timerWelcome.Stop();
this.Hide();
}
}
}
}
}
对应设计器:
MainForm窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Threading;
namespace 原神UP角色抽卡模拟器
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
#region 声明变量与数据的代码段
string[] Name_All_Ch = new string[72] {"赛诺","提纳里","迪希雅","刻晴","莫娜","七七","迪卢克","琴","香菱","久岐忍","绮良良","菲米尼","琳妮特","卡维","米卡","瑶瑶","珐露珊","莱依拉","坎蒂丝","多莉","柯莱","云堇","鹿野院平藏","九条裟罗","五郎","早柚","托马","烟绯","罗莎莉亚","辛焱","砂糖","迪奥娜","重云","诺艾尔","班尼特","菲谢尔","凝光","行秋","北斗","雷泽","芭芭拉","弓藏","祭礼弓","绝弦","西风猎弓","昭心","祭礼残章","流浪乐章","西风秘典","西风长枪","匣里灭辰","雨裁","祭礼大剑","钟剑","西风大剑","匣里龙吟","祭礼剑","笛剑","西风剑","弹弓","神射手之誓","鸦羽弓","翡玉法球","讨龙英杰谭","魔导绪论","黑缨枪","以理服人","沐浴龙血的剑","铁影阔剑","飞天御剑","黎明神剑","冷刃"};
public PrayerShowForm PSF = null;
public HistoryForm HF = null;
public int Number_Totle = 0;//总计抽奖数量
public int Number_5Star = 0;//保底累计数量
bool Big_5Star = false;//大保底与否
Panel P_ObjectInfomation = null;
Label L_ObjectInfomation = null;
Thread ThreadUpdateMasterless = null;
int Num_MasterlessStarglitter = 0, Num_MasterlessStardust = 0;//星辉与星尘的数量
string[,] HistoryRecord = new string[1000,5];//储存历史记录的字符串数组,第二维度的0表示星数
#endregion
private void MainForm_Load(object sender, EventArgs e)
{
label_IntertwinedFate.BackColor = label_MasterlessStardust.BackColor = label_MasterlessStarglitter.BackColor = label_Primogem.BackColor = Color.FromArgb(0, 0, 0, 0);
label_IntertwinedFate.ForeColor = label_MasterlessStardust.ForeColor = label_MasterlessStarglitter.ForeColor = label_Primogem.ForeColor = Color.White;
pictureBox_Info.BackColor = pictureBox_History.BackColor = pictureBox_Prayer_1.BackColor = pictureBox_Prayer_10.BackColor = pictureBox_About.BackColor = Color.FromArgb(0, 0, 0, 0);
label_MasterlessStardust.Text = label_MasterlessStarglitter.Text = label_IntertwinedFate.Text = label_Primogem.Text = "0";
panel_Info.Visible = panel_History.Visible = panel_P1.Visible = panel_P10.Visible = panel_About.Visible = false;
pictureBox_Return.Size = new Size(0, 40);
pictureBox_Return.BackColor = Color.FromArgb(0, 0, 0, 0);
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private void label_Primogem_Click(object sender, EventArgs e)
{//这是“原石”
if (P_ObjectInfomation == null)
{
pictureBox_Return.Width = 40;
pictureBox_Return.SizeMode = PictureBoxSizeMode.Zoom;
P_ObjectInfomation = new Panel();
P_ObjectInfomation.Size = new Size(329, 301);
P_ObjectInfomation.Location = new Point(this.Width / 2 - P_ObjectInfomation.Width / 2, this.Height / 2 - P_ObjectInfomation.Height / 2);
P_ObjectInfomation.BackgroundImage = Image.FromFile("bins\\Primogem.png");
P_ObjectInfomation.BackgroundImageLayout = ImageLayout.Zoom;
this.Controls.Add(P_ObjectInfomation);
P_ObjectInfomation.BringToFront();
}
}
private void label_IntertwinedFate_Click(object sender, EventArgs e)
{//这是“纠缠之缘”
if (P_ObjectInfomation == null)
{
pictureBox_Return.Width = 40;
pictureBox_Return.SizeMode = PictureBoxSizeMode.Zoom;
P_ObjectInfomation = new Panel();
P_ObjectInfomation.Size = new Size(328, 309);
P_ObjectInfomation.Location = new Point(this.Width / 2 - P_ObjectInfomation.Width / 2, this.Height / 2 - P_ObjectInfomation.Height / 2);
P_ObjectInfomation.BackgroundImage = Image.FromFile("bins\\IntertwinedFate.png");
P_ObjectInfomation.BackgroundImageLayout = ImageLayout.Zoom;
this.Controls.Add(P_ObjectInfomation);
P_ObjectInfomation.BringToFront();
}
}
private void label_MasterlessStarglitter_Click(object sender, EventArgs e)
{//这是“星辉”
if (P_ObjectInfomation == null)
{
pictureBox_Return.Width = 40;
pictureBox_Return.SizeMode = PictureBoxSizeMode.Zoom;
P_ObjectInfomation = new Panel();
P_ObjectInfomation.Size = new Size(330, 408);
P_ObjectInfomation.Location = new Point(this.Width / 2 - P_ObjectInfomation.Width / 2, this.Height / 2 - P_ObjectInfomation.Height / 2);
P_ObjectInfomation.BackgroundImage = Image.FromFile("bins\\MasterlessStarglitter.png");
P_ObjectInfomation.BackgroundImageLayout = ImageLayout.Zoom;
this.Controls.Add(P_ObjectInfomation);
P_ObjectInfomation.BringToFront();
}
if (L_ObjectInfomation == null)
{
L_ObjectInfomation = new Label();
L_ObjectInfomation.Text = Num_MasterlessStarglitter.ToString();
L_ObjectInfomation.Font = new Font("华文中宋", 12, FontStyle.Bold);
L_ObjectInfomation.Location = new Point(193, 381);
L_ObjectInfomation.ForeColor = Color.SteelBlue;
L_ObjectInfomation.BackColor = Color.FromArgb(0, 0, 0, 0);
P_ObjectInfomation.Controls.Add(L_ObjectInfomation);
}
}
private void label_MasterlessStardust_Click(object sender, EventArgs e)
{//这是“星尘”
if (P_ObjectInfomation == null)
{
pictureBox_Return.Width = 40;
pictureBox_Return.SizeMode = PictureBoxSizeMode.Zoom;
P_ObjectInfomation = new Panel();
P_ObjectInfomation.Size = new Size(330, 407);
P_ObjectInfomation.Location = new Point(this.Width / 2 - P_ObjectInfomation.Width / 2, this.Height / 2 - P_ObjectInfomation.Height / 2);
P_ObjectInfomation.BackgroundImage = Image.FromFile("bins\\MasterlessStardust.png");
P_ObjectInfomation.BackgroundImageLayout = ImageLayout.Zoom;
this.Controls.Add(P_ObjectInfomation);
P_ObjectInfomation.BringToFront();
}
if (L_ObjectInfomation == null)
{
L_ObjectInfomation = new Label();
L_ObjectInfomation.Text = Num_MasterlessStardust.ToString();
L_ObjectInfomation.Font = new Font("华文中宋", 12, FontStyle.Bold);
L_ObjectInfomation.Location = new Point(190, 381);
L_ObjectInfomation.ForeColor = Color.SteelBlue;
L_ObjectInfomation.BackColor = Color.FromArgb(0, 0, 0, 0);
P_ObjectInfomation.Controls.Add(L_ObjectInfomation);
}
}
private void pictureBox_Exit_Paint(object sender, PaintEventArgs e)
{//将这个控件的边界绘制成圆形
int SideLength = (pictureBox_Exit.Height + pictureBox_Exit.Width) / 2;
Graphics g = e.Graphics;// 创建一个画布对象
// 创建一个矩形对象,表示PictureBox的区域
Rectangle rect = new Rectangle(0, 0, SideLength, SideLength);
// 创建一个画笔对象,用于绘制圆形边框
Pen pen = new Pen(Color.Black); // 设置边框颜色为黑色
pen.Width = 1; // 设置边框宽度为2像素
g.DrawEllipse(pen, rect);// 绘制圆形边框
pictureBox_ExitBackground.BackColor = pictureBox_Exit.BackColor = Color.FromArgb(0, 0, 0, 0);//背景设置为透明
pictureBox_ExitBackground.Visible = false;
}
private void pictureBox_Exit_MouseEnter(object sender, EventArgs e)
{
pictureBox_ExitBackground.Visible = true;
}
private void pictureBox_Exit_MouseLeave(object sender, EventArgs e)
{
pictureBox_ExitBackground.Visible = false;
}
private void pictureBox_Exit_Click(object sender, EventArgs e)
{
AskForLeave AFL = new AskForLeave();//询问是否要退出
AFL.Show();
}
private void pictureBox_Prayer_1_Click(object sender, EventArgs e)
{//单抽
if (ThreadUpdateMasterless != null)
{
ThreadUpdateMasterless.Interrupt();
ThreadUpdateMasterless = null;
}
if (P_ObjectInfomation == null)
{
int[] Code=new int[1];//储存抽到的物品/角色的编码
Code[0] = Prayer();
PSF = new PrayerShowForm(1, Code);//单抽传值
PSF.Show();
}
ThreadUpdateMasterless = new Thread(new ThreadStart(Thread_Masterless));
ThreadUpdateMasterless.Start();
}
private void pictureBox_Prayer_10_Click(object sender, EventArgs e)
{//十连抽
if (ThreadUpdateMasterless != null)
{
ThreadUpdateMasterless.Interrupt();
ThreadUpdateMasterless = null;
}
if (P_ObjectInfomation == null)
{
int[] Code = new int[10];//储存抽到的物品/角色的编码
for (int i=0;i<10;i++)
Code[i] = Prayer();
PSF = new PrayerShowForm(10, Code);//十连抽传值
PSF.Show();
}
ThreadUpdateMasterless = new Thread(new ThreadStart(Thread_Masterless));
ThreadUpdateMasterless.Start();
}
private void pictureBox_Info_Click(object sender, EventArgs e)
{
if (P_ObjectInfomation == null)
{
InformationForm IF = new InformationForm();
IF.Show();
}
}
private void pictureBox_History_Click(object sender, EventArgs e)
{
if (P_ObjectInfomation == null)
{
HF = new HistoryForm(Number_Totle,HistoryRecord);
HF.Show();
}
}
private void pictureBox_Info_MouseEnter(object sender, EventArgs e)
{
panel_Info.Visible = true;
}
private void pictureBox_Info_MouseLeave(object sender, EventArgs e)
{
panel_Info.Visible = false;
}
private void pictureBox_History_MouseEnter(object sender, EventArgs e)
{
panel_History.Visible = true;
}
private void pictureBox_History_MouseLeave(object sender, EventArgs e)
{
panel_History.Visible = false;
}
private void pictureBox_Prayer_1_MouseEnter(object sender, EventArgs e)
{
panel_P1.Visible = true;
}
private void pictureBox_Prayer_1_MouseLeave(object sender, EventArgs e)
{
panel_P1.Visible = false;
}
private void pictureBox_Prayer_10_MouseEnter(object sender, EventArgs e)
{
panel_P10.Visible = true;
}
private void pictureBox_Prayer_10_MouseLeave(object sender, EventArgs e)
{
panel_P10.Visible = false;
}
private void pictureBox_Return_Click(object sender, EventArgs e)
{
if (L_ObjectInfomation != null)
{
P_ObjectInfomation.Controls.Remove(L_ObjectInfomation);
L_ObjectInfomation = null;
}
if (P_ObjectInfomation!=null)
{
this.Controls.Remove(P_ObjectInfomation);
P_ObjectInfomation = null;
pictureBox_Return.Width = 0;
}
}
private int Prayer()
{//自定义的得到单次抽奖的编码的函数
int randNumber;
int Code = 1;
if (Number_Totle!=1000) Number_Totle++;
else
for (int i = 1; i < 1000; i++)
for (int j = 0; j < 5; j++)
HistoryRecord[i - 1, j] = HistoryRecord[i, j];
Number_5Star++;
if (Number_5Star%10!=0)//没有保底的情况
{
randNumber = Rand(10000);//生成一个1-10000的随机数
if (randNumber>=1 && randNumber<=60)//抽到了5星角色
{//50%概率为UP
Number_5Star = 0;
randNumber = Rand(2);//生成1或2,模拟50%概率
if (randNumber==1)//非UP的5星角色
{
Big_5Star = true;
randNumber = Rand(7);//生成1-7的随机数,模拟7选1
Code = randNumber + 1;///所得Code范围为[2,8]
}
else//5星UP
{
Big_5Star = false;
Code = 1;///所得Code范围为{1}
}
}
else if (randNumber >= 61 && randNumber <= 315)//抽到了4星角色
{//50%概率为UP
randNumber = Rand(2);//生成1或2,模拟50%概率
if (randNumber==1)//抽到了4星UP角色
{
randNumber = Rand(3);//1,2或3,三选一
Code = 8 + randNumber;///所得Code范围为[9,11]
}
else//4星非UP角色
{
randNumber = Rand(30);//1-30的随机数,即总共30个非UP的4星角色
Code = 11 + randNumber;///所得Code范围为[12,41]
}
}
else if (randNumber >= 316 && randNumber <= 570)//抽到了4星物品
{
randNumber = Rand(18);//18件4星物品
Code = 41 + randNumber;///所得Code范围为[42,59]
}
else//3星
{
randNumber = Rand(13);//13件3星物品
Code = 59 + randNumber;///所得Code范围为[60,72]
}
}
else//有保底的情况
{
if (Number_5Star==90)//5星保底
{
Number_5Star = 0;
if (Big_5Star)//是大保底
{
Big_5Star = false;
Code = 1;///所得Code范围为{1}
}
else//是小保底
{
Big_5Star = true;
randNumber = Rand(7);//生成1-7的随机数,模拟7选1
Code = randNumber + 1;///所得Code范围为[2,8]
}
}
else//10抽的保底(99.4%为4星)
{
randNumber = Rand(1000);//1-1000的随机数
if (randNumber>=1&&randNumber<=994)//每10抽的保底为4星
{
//50%概率为UP
randNumber = Rand(2);//生成1或2,模拟50%概率
if (randNumber == 1)//抽到了4星UP角色
{
randNumber = Rand(3);//1,2或3,三选一
Code = 8 + randNumber;///所得Code范围为[9,11]
}
else//4星非UP角色
{
randNumber = Rand(30);//1-30的随机数,即总共30个非UP的4星角色
Code = 11 + randNumber;///所得Code范围为[12,41]
}
}
else//0.4%g
{
}
}
}//以上代码根据游戏内描述得到了一个Code编码,范围为[1,72]
//写入历史记录
HistoryRecord[Number_Totle - 1, 0] = StarNumber(Code).ToString();
if (Code>=1&&Code<=41) HistoryRecord[Number_Totle - 1, 1] = "角色";
else HistoryRecord[Number_Totle - 1, 1] = "武器";
if (Code - 1 >= 0 && Code - 1 <= 71)
HistoryRecord[Number_Totle - 1, 2] = Name_All_Ch[Code - 1];//
else MessageBox.Show("随机数据出错:"+(Code - 1).ToString()+"。请向开发者反馈,主页:sherrychou.blog.csdn.net", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
HistoryRecord[Number_Totle - 1, 3] = "活动祈愿";
HistoryRecord[Number_Totle - 1, 4] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
return Code;
}
private int StarNumber(int Code)
{
if (Code >= 1 && Code <= 8) return 5;
if (Code >= 9 && Code <= 59) return 4;
if (Code >= 60 && Code <= 72) return 3;
return 0;
}//用于对物品/角色编码返回对应星级的函数
private int Rand(int N)
{//生成1-N的随机数的函数,使用RNGCryptoServiceProvider类生成随机数
RNGCryptoServiceProvider cryptoServiceProvider = new RNGCryptoServiceProvider();
byte[] randomBuffer = new byte[4]; // 4字节 * 8 = 32位随机数
cryptoServiceProvider.GetBytes(randomBuffer);
int randomInt = BitConverter.ToInt32(randomBuffer, 0);
if (randomInt < 0) randomInt = -randomInt;
int Ans = randomInt % N + 1;
return Ans;
}
private void pictureBox_About_MouseEnter(object sender, EventArgs e)
{
pictureBox_About.Image = Image.FromFile("bins\\About_2.png");
panel_About.Visible = true;
}
private void pictureBox_About_MouseLeave(object sender, EventArgs e)
{
pictureBox_About.Image = Image.FromFile("bins\\About_1.png");
panel_About.Visible = false;
}
private void pictureBox_About_Click(object sender, EventArgs e)
{//进入“关于”页面
AboutForm AF = new AboutForm();
AF.Show();
}
private void Thread_Masterless()
{//用于“无主的星辉”与“无主的星尘”的累加
Num_MasterlessStardust = Num_MasterlessStarglitter = 0;
for (int i = Number_Totle-1; i >= 0; i--)
{
for (int j = i - 1; j >= 0; j--)
if ((HistoryRecord[i, 2] == HistoryRecord[j, 2]) && (HistoryRecord[j, 1] == "角色"))
if (HistoryRecord[j, 0] == "5")
Num_MasterlessStarglitter += 10;
else Num_MasterlessStarglitter += 2;
if (HistoryRecord[i, 1] == "武器")
if (HistoryRecord[i, 0] == "4")
Num_MasterlessStarglitter += 2;
else Num_MasterlessStardust += 15;
}
Invoke(new Action(() =>
{
label_MasterlessStarglitter.Text = Num_MasterlessStarglitter.ToString();
label_MasterlessStardust.Text = Num_MasterlessStardust.ToString();
}));//跨线程操作
}
}
}
对应设计器:
PrayerShowForm窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;//使用线程
namespace 原神UP角色抽卡模拟器
{
public partial class PrayerShowForm : Form
{
public PrayerShowForm(int N,int[] Code)
{
InitializeComponent();
Prayer_N = N;//记录传递过来的数据,Prayer_N即为单次祈愿次数(单抽或十连抽)
T_BF = new Thread(() => Thread_BasicForm(Prayer_N));//适配有参数的线程的定义与赋值
T_BF.Start();//启动线程
#region 将pictureBox控件放入Control数组便于管理与使用
PictureBoxArray[0] = pictureBox1;
PictureBoxArray[1] = pictureBox2;
PictureBoxArray[2] = pictureBox3;
PictureBoxArray[3] = pictureBox4;
PictureBoxArray[4] = pictureBox5;
PictureBoxArray[5] = pictureBox6;
PictureBoxArray[6] = pictureBox7;
PictureBoxArray[7] = pictureBox8;
PictureBoxArray[8] = pictureBox9;
PictureBoxArray[9] = pictureBox10;
#endregion
#region 将panel控件放入StarNumber_Color数组便于管理与使用
StarNumber_Color[0] = panel1;
StarNumber_Color[1] = panel2;
StarNumber_Color[2] = panel3;
StarNumber_Color[3] = panel4;
StarNumber_Color[4] = panel5;
StarNumber_Color[5] = panel6;
StarNumber_Color[6] = panel7;
StarNumber_Color[7] = panel8;
StarNumber_Color[8] = panel9;
StarNumber_Color[9] = panel10;
#endregion
//将抽到的Code编码储存进变量
for (int i = 0; i < N; i++)
CodeOfIncome[i] = Code[i];
}
#region 声明变量的代码
/*1为5星UP
* 2-8为5星非UP
* 9-11为4星UP角色
* 12-41为4星非UP角色
* 42-59为4星武器
* 60-72为3星武器*/
string[] Name_All = new string[72] {"Cyno","Tighnari","Dehya","Keqing","Mona","Qiqi","Diluc","Jean","Xiangling","KukiShinobu","Kirara","Freminet","Lynette","Kaveh","Mika","Yaoyao","Faruzan","Lyala","Candace","Dori","Collei","Yunjin","ShikanoinHeizou","Kujosara","Gorou","Sayu","Thoma","Yanfei","Rosaria","Xinyan","Sucrose","Diona","Chongyun","Noelle","Bennett","Fischl","Ningguang","Xingqiu","Beidou","Razor","Barbara","Rust","SacrificialBow","TheStringless","FavoniusWarbow","EyeOfPerception","SacrificialFragments","TheWidsith","FavoniusCodex","FavoniusLance","Dragon'sBane","Rainslasher","SacrificialGreatsword","TheBell","FavoniusGreatsword","Lion'sRoar","SacrificialSword","TheFlute","FavoniusSword","Slingshot","Sharpshooter'sOath","RavenBow","EmeraldOrb","ThrillingTalesOfDragonSlayers","MagicGuide","BlackTassel","DebateClub","BloodtaintedGreatsword","FerrousShadow","SkyriderSword","HarbingerOfDawn","CoolSteel"};
int Prayer_N = 0, CartoonTimerCounter=0;
Control[] PictureBoxArray = new Control[10];//储存pictureBox控件中用于展示抽中结果的部分
Thread T_BF = null;
Panel[] StarNumber_Color = new Panel[10];
string VideoPath = "";
int[] CodeOfIncome = new int[10];
#endregion
private void Thread_BasicForm(int N)
{//用于布置基本页面的线程,十连抽不用动,单抽需要动
if (N==1)
{
Invoke(new Action(() =>
{
PictureBoxArray[0].Location = new Point(this.Width/2-PictureBoxArray[0].Width/2,(this.Height-PictureBoxArray[0].Height)/2);
StarNumber_Color[0].Location = new Point(PictureBoxArray[0].Location.X, StarNumber_Color[0].Location.Y);
}));//跨线程操作
for (int i = 1; i < 10; i++)
Invoke(new Action(() =>
{
StarNumber_Color[i].Visible = PictureBoxArray[i].Visible = false;//让其他控件不可见实现隐藏
}));//跨线程操作
}//页面运行时间不长,就不再考虑线程占用内存的问题了
}
private void PrayerShowForm_Load(object sender, EventArgs e)
{
this.CenterToScreen();//将窗体居中
pictureBox_Exit.BackColor = pictureBox_ExitBackground.BackColor = Color.FromArgb(0, 0, 0, 0);
axWindowsMediaPlayer_Cartoon.Width = 1600;
axWindowsMediaPlayer_Cartoon.Height = 1100;
VideoPath = "bins\\Prayer_10_5.mp4";
switch (Prayer_N)
{
case 1:
VideoPath = "bins\\Prayer_1_" + StarNumber(CodeOfIncome[0]).ToString() + ".mp4";
PictureBoxArray[0].BackgroundImage = Image.FromFile("bins\\sources\\" + Name_All[CodeOfIncome[0]] + ".png");
PictureBoxArray[0].BackgroundImageLayout = ImageLayout.Zoom;
switch (StarNumber(CodeOfIncome[0]))
{
case 3:StarNumber_Color[0].BackColor = Color.CornflowerBlue; break;
case 4:StarNumber_Color[0].BackColor = Color.Purple;break;
case 5:StarNumber_Color[0].BackColor = Color.Goldenrod;break;
}
break;
case 10:
{
int MaxStar = 0;
for (int i = 0; i < 10; i++)
MaxStar = (StarNumber(CodeOfIncome[i]) > MaxStar) ? StarNumber(CodeOfIncome[i]) : MaxStar;
VideoPath = "bins\\Prayer_10_" + MaxStar.ToString() + ".mp4";
for (int i=0;i<10;i++)
for (int j=0;j<9-i;j++)
if (CodeOfIncome[j] > CodeOfIncome[j + 1])//Code越靠前,星数越多
{
int temp = CodeOfIncome[j];
CodeOfIncome[j] = CodeOfIncome[j + 1];
CodeOfIncome[j + 1] = temp;
}//进行排序,降序
for (int i=0;i<10;i++)
{
PictureBoxArray[i].BackgroundImage = Image.FromFile("bins\\sources\\" + Name_All[CodeOfIncome[i] - 1] + ".png");
PictureBoxArray[i].BackgroundImageLayout = ImageLayout.Zoom;
switch (StarNumber(CodeOfIncome[i]))
{
case 3: StarNumber_Color[i].BackColor = Color.CornflowerBlue; break;
case 4: StarNumber_Color[i].BackColor = Color.Purple; break;
case 5: StarNumber_Color[i].BackColor = Color.Goldenrod; break;
}
}
break;
}
}
axWindowsMediaPlayer_Cartoon.URL = VideoPath;
}
private void axWindowsMediaPlayer_Cartoon_DoubleClickEvent(object sender, AxWMPLib._WMPOCXEvents_DoubleClickEvent e)
{
}
private void timer_Cartoon_Tick(object sender, EventArgs e)
{
CartoonTimerCounter++;
if (CartoonTimerCounter == 64)
{
axWindowsMediaPlayer_Cartoon.Visible = false;
CartoonTimerCounter = 0;
pictureBox1_Skip.Visible = false;
timer_Cartoon.Stop();
}
}
private void pictureBox_Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void pictureBox_Exit_MouseEnter(object sender, EventArgs e)
{
pictureBox_ExitBackground.Visible = true;
}
private void pictureBox_Exit_MouseLeave(object sender, EventArgs e)
{
pictureBox_ExitBackground.Visible = false;
}
private void pictureBox_Exit_Paint(object sender, PaintEventArgs e)
{//将这个控件的边界绘制成圆形
int SideLength = (pictureBox_Exit.Height + pictureBox_Exit.Width) / 2;
Graphics g = e.Graphics;// 创建一个画布对象
// 创建一个矩形对象,表示PictureBox的区域
Rectangle rect = new Rectangle(0, 0, SideLength, SideLength);
// 创建一个画笔对象,用于绘制圆形边框
Pen pen = new Pen(Color.Black); // 设置边框颜色为黑色
pen.Width = 1; // 设置边框宽度为2像素
g.DrawEllipse(pen, rect);// 绘制圆形边框
pictureBox_ExitBackground.BackColor = pictureBox_Exit.BackColor = Color.FromArgb(0, 0, 0, 0);//背景设置为透明
pictureBox_ExitBackground.Visible = false;
}
private void pictureBox_ExitBackground_Paint(object sender, PaintEventArgs e)
{//将这个控件的边界绘制成圆形
int SideLength = (pictureBox_ExitBackground.Height + pictureBox_ExitBackground.Width) / 2;
Graphics g = e.Graphics;// 创建一个画布对象
// 创建一个矩形对象,表示PictureBox的区域
Rectangle rect = new Rectangle(0, 0, SideLength, SideLength);
// 创建一个画笔对象,用于绘制圆形边框
Pen pen = new Pen(Color.Black); // 设置边框颜色为黑色
pen.Width = 1; // 设置边框宽度为2像素
g.DrawEllipse(pen, rect);// 绘制圆形边框
}
private void pictureBox1_Skip_Click(object sender, EventArgs e)
{
timer_Cartoon.Stop();
axWindowsMediaPlayer_Cartoon.Visible = false;
axWindowsMediaPlayer_Cartoon.URL = "";
pictureBox1_Skip.Visible = false;
}
private int StarNumber(int Code) {
if (Code >= 1 && Code <= 8) return 5;
if (Code >= 9 && Code <= 59) return 4;
if (Code >= 60 && Code <= 72) return 3;
return 0;
}//用于对物品/角色编码返回对应星级的函数
}
}
对应设计器:
InformationForm窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 原神UP角色抽卡模拟器
{
public partial class InformationForm : Form
{
public InformationForm()
{
InitializeComponent();
pictureBox_Info.MouseWheel += new MouseEventHandler(pictureBox_Inf_MouseWheel);
}
private void InformationForm_Load(object sender, EventArgs e)
{
pictureBox_Exit.BackColor = Color.FromArgb(0, 0, 0, 0);
}
#region 变量的声明
private bool dragging = false;
private Point dragCursorPoint;
private Point dragFormPoint;
bool MouseWheelMove = false;
#endregion
private void pictureBox_Exit_Paint(object sender, PaintEventArgs e)
{//将这个控件的边界绘制成圆形
int SideLength = (pictureBox_Exit.Height + pictureBox_Exit.Width) / 2;
Graphics g = e.Graphics;// 创建一个画布对象
// 创建一个矩形对象,表示PictureBox的区域
Rectangle rect = new Rectangle(0, 0, SideLength, SideLength);
// 创建一个画笔对象,用于绘制圆形边框
Pen pen = new Pen(Color.Black); // 设置边框颜色为黑色
pen.Width = 1; // 设置边框宽度为2像素
g.DrawEllipse(pen, rect);// 绘制圆形边框
}
private void pictureBox_Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void pictureBox_Info_MouseDown(object sender, MouseEventArgs e)
{
dragging = true;
dragCursorPoint = Cursor.Position;
dragFormPoint = pictureBox_Info.Location;
}
private void pictureBox_Info_MouseUp(object sender, MouseEventArgs e)
{
dragging = false;
}
private void pictureBox_Info_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
Point dif = Point.Subtract(Cursor.Position, new Size(dragCursorPoint));
int minY = -(pictureBox_Info.Height - panel_Info.Height); // 最小 y 坐标
int maxY = 0; // 最大 y 坐标
int y = pictureBox_Info.Location.Y + dif.Y/50;
if (y >= minY && y <= maxY)
pictureBox_Info.Location = new Point(pictureBox_Info.Location.X, y);
else
{
if (y < minY) pictureBox_Info.Location = new Point(pictureBox_Info.Location.X, minY);
if (y > maxY) pictureBox_Info.Location = new Point(pictureBox_Info.Location.X, maxY);
}
}
}
private void pictureBox_Info_MouseEnter(object sender, EventArgs e)
{
MouseWheelMove = true;
pictureBox_Info.Focus();
}
private void pictureBox_Info_Click(object sender, EventArgs e)
{
}
private void pictureBox_Inf_MouseWheel(object sender, MouseEventArgs e)
{//使用鼠标滚轮进行控制的操作
if (MouseWheelMove)
{
int minY = -(pictureBox_Info.Height - panel_Info.Height); // 最小 y 坐标
int maxY = 0; // 最大 y 坐标
int y = pictureBox_Info.Location.Y + e.Delta / Math.Abs(e.Delta) * 100;
if (y >= minY && y <= maxY)
pictureBox_Info.Location = new Point(pictureBox_Info.Location.X, y);
else
{
if (y < minY) pictureBox_Info.Location = new Point(pictureBox_Info.Location.X, minY);
if (y > maxY) pictureBox_Info.Location = new Point(pictureBox_Info.Location.X, maxY);
}
}
}
private void pictureBox_Info_MouseLeave(object sender, EventArgs e)
{
MouseWheelMove = false;
}
}
}
对应设计器:
HistoryForm窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 原神UP角色抽卡模拟器
{
public partial class HistoryForm : Form
{
public HistoryForm(int N,string[,] History)
{
InitializeComponent();
N_History = N;
for (int i = 0; i < N_History; i++)
for (int j = 0; j < 5; j++)
HistoryRecord[i,j] = History[i,j];//数据的转存
MaxPage = (N_History - 1) / 5 + 1;//最多到第几页
#region 将label矩阵存入二维数组LabelMatrix的代码块
LabelMatrix[0, 0] = label_1_1;
LabelMatrix[0, 1] = label_1_2;
LabelMatrix[0, 2] = label_1_3;
LabelMatrix[0, 3] = label_1_4;
LabelMatrix[1, 0] = label_2_1;
LabelMatrix[1, 1] = label_2_2;
LabelMatrix[1, 2] = label_2_3;
LabelMatrix[1, 3] = label_2_4;
LabelMatrix[2, 0] = label_3_1;
LabelMatrix[2, 1] = label_3_2;
LabelMatrix[2, 2] = label_3_3;
LabelMatrix[2, 3] = label_3_4;
LabelMatrix[3, 0] = label_4_1;
LabelMatrix[3, 1] = label_4_2;
LabelMatrix[3, 2] = label_4_3;
LabelMatrix[3, 3] = label_4_4;
LabelMatrix[4, 0] = label_5_1;
LabelMatrix[4, 1] = label_5_2;
LabelMatrix[4, 2] = label_5_3;
LabelMatrix[4, 3] = label_5_4;
#endregion
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(HistoryForm_MouseWheel);
}
#region 声明变量的代码段
string[,] HistoryRecord = new string[1000,5];//二维数组
//HistoryRecord[i,0]表示的时第i条历史记录所得的星数,其余与页面所需一一对应
int N_History = 0;
int CurrentPage = 1, MaxPage;
Control[,] LabelMatrix = new Control[5, 4];
int[] ChartArrange_X = new int[4] { 230, 380, 560, 760 };//各列的中心X坐标
int[] ChartLine_Y = new int[5] { 319, 354, 389, 424, 459 };//各行的中心Y坐标
bool PageChange_MouseWheel = false;
#endregion
private void HistoryForm_Load(object sender, EventArgs e)
{
#region 将控件背景设置为透明的代码
for (int i = 0; i < 5; i++)
for (int j = 0; j < 4; j++)
{
LabelMatrix[i, j].BackColor = Color.FromArgb(0, 0, 0, 0);
LabelMatrix[i, j].Text = "";
}
label_Page.BackColor = pictureBox_Exit.BackColor = Color.FromArgb(0, 0, 0, 0);
pictureBox_PageDown.BackColor = pictureBox_PageUp.BackColor = Color.FromArgb(0, 0, 0, 0);
#endregion
label_Page.Location = new Point(this.Width / 2 - label_Page.Width / 2 - 14, label_Page.Location.Y);//居中
//接下来显示历史记录第一页
int Temp = (5 > N_History)? (N_History - 1) : 4;
for (int i = Temp; i >= 0; i--)
{
for (int j = 0; j < 4; j++)
{//第Temp - i + 1行,第j + 1列
LabelMatrix[Temp - i, j].Text = HistoryRecord[N_History - Temp - 1 + i, j + 1];
LabelMatrix[Temp - i, j].Location = new Point(ChartArrange_X[j] - LabelMatrix[Temp - i, j].Width / 2, ChartLine_Y[Temp - i] - LabelMatrix[Temp - i, j].Height / 2);
}
switch (HistoryRecord[N_History - Temp - 1 + i, 0])
{
case "3": LabelMatrix[Temp - i, 1].ForeColor = Color.Black; break;
case "4": LabelMatrix[Temp - i, 1].ForeColor = Color.Purple; break;
case "5": LabelMatrix[Temp - i, 1].ForeColor = Color.Goldenrod; break;
}
}
}
private void pictureBox_Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void pictureBox_PageDown_Click(object sender, EventArgs e)
{
if (CurrentPage<MaxPage)
{
CurrentPage++;
label_Page.Text = CurrentPage.ToString();
label_Page.Location = new Point(this.Width / 2 - label_Page.Width / 2 - 14, label_Page.Location.Y);//居中
for (int i = 0; i < 5; i++)
{
int Line = N_History - (CurrentPage - 1) * 5 - i - 1;
for (int j = 0; j < 4; j++)
if (Line >= 0)
{
LabelMatrix[i, j].Text = HistoryRecord[Line, j + 1];
LabelMatrix[i, j].Location = new Point(ChartArrange_X[j] - LabelMatrix[i, j].Width / 2, ChartLine_Y[i] - LabelMatrix[i, j].Height / 2);
}
else LabelMatrix[i, j].Text = "";
if (Line >= 0) switch (HistoryRecord[Line, 0])
{
case "3": LabelMatrix[i, 1].ForeColor = Color.Black; break;
case "4": LabelMatrix[i, 1].ForeColor = Color.Purple; break;
case "5": LabelMatrix[i, 1].ForeColor = Color.Goldenrod; break;
}
}
}
}
private void pictureBox_PageUp_DoubleClick(object sender, EventArgs e)
{
if (CurrentPage > 1)
{
if (CurrentPage == 2) CurrentPage = 1;
else CurrentPage -= 2;
label_Page.Text = CurrentPage.ToString();
label_Page.Location = new Point(this.Width / 2 - label_Page.Width / 2 - 14, label_Page.Location.Y);//居中
for (int i = 0; i < 5; i++)
{
int Line = N_History - (CurrentPage - 1) * 5 - i - 1;
for (int j = 0; j < 4; j++)
if (Line >= 0)
{
LabelMatrix[i, j].Text = HistoryRecord[Line, j + 1];
LabelMatrix[i, j].Location = new Point(ChartArrange_X[j] - LabelMatrix[i, j].Width / 2, ChartLine_Y[i] - LabelMatrix[i, j].Height / 2);
}
else LabelMatrix[i, j].Text = "";
if (Line >= 0) switch (HistoryRecord[Line, 0])
{
case "3": LabelMatrix[i, 1].ForeColor = Color.Black; break;
case "4": LabelMatrix[i, 1].ForeColor = Color.Purple; break;
case "5": LabelMatrix[i, 1].ForeColor = Color.Goldenrod; break;
}
}
}
}
private void pictureBox_PageDown_DoubleClick(object sender, EventArgs e)
{
if (CurrentPage < MaxPage)
{
if (CurrentPage == MaxPage - 1) CurrentPage = MaxPage;
else CurrentPage += 2;
label_Page.Text = CurrentPage.ToString();
label_Page.Location = new Point(this.Width / 2 - label_Page.Width / 2 - 14, label_Page.Location.Y);//居中
for (int i = 0; i < 5; i++)
{
int Line = N_History - (CurrentPage - 1) * 5 - i - 1;
for (int j = 0; j < 4; j++)
if (Line >= 0)
{
LabelMatrix[i, j].Text = HistoryRecord[Line, j + 1];
LabelMatrix[i, j].Location = new Point(ChartArrange_X[j] - LabelMatrix[i, j].Width / 2, ChartLine_Y[i] - LabelMatrix[i, j].Height / 2);
}
else LabelMatrix[i, j].Text = "";
if (Line >= 0) switch (HistoryRecord[Line, 0])
{
case "3": LabelMatrix[i, 1].ForeColor = Color.Black; break;
case "4": LabelMatrix[i, 1].ForeColor = Color.Purple; break;
case "5": LabelMatrix[i, 1].ForeColor = Color.Goldenrod; break;
}
}
}
}
private void pictureBox_PageUp_Click(object sender, EventArgs e)
{
if (CurrentPage > 1)
{
CurrentPage--;
label_Page.Text = CurrentPage.ToString();
label_Page.Location = new Point(this.Width / 2 - label_Page.Width / 2 - 14, label_Page.Location.Y);//居中
for(int i=0;i<5;i++)
{
int Line = N_History - (CurrentPage - 1) * 5 - i - 1;
for (int j = 0; j < 4; j++)
if (Line >= 0)
{
LabelMatrix[i, j].Text = HistoryRecord[Line, j + 1];
LabelMatrix[i, j].Location = new Point(ChartArrange_X[j] - LabelMatrix[i, j].Width / 2, ChartLine_Y[i] - LabelMatrix[i, j].Height / 2);
}
else LabelMatrix[i, j].Text = "";
if (Line >= 0) switch (HistoryRecord[Line, 0])
{
case "3": LabelMatrix[i, 1].ForeColor = Color.Black; break;
case "4": LabelMatrix[i, 1].ForeColor = Color.Purple; break;
case "5": LabelMatrix[i, 1].ForeColor = Color.Goldenrod; break;
}
}
}
}
#region 没必要看的代码
private void HistoryForm_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void HistoryForm_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_1_1_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_1_1_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_1_2_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_1_2_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_1_3_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_1_3_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_1_4_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_1_4_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_2_1_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_2_1_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_2_2_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_2_2_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_2_3_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_2_3_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_2_4_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_2_4_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_3_1_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_3_1_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_3_2_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_3_2_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_3_3_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_3_4_Click(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_3_3_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_3_4_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_3_4_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_4_1_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_4_1_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_4_2_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_4_2_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_4_3_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_4_3_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_4_4_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_4_4_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_5_1_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_5_1_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_5_2_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_5_2_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_5_3_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_5_3_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_5_4_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_5_4_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void label_Page_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void label_Page_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
private void pictureBox_Exit_MouseEnter(object sender, EventArgs e)
{
PageChange_MouseWheel = true;
this.Focus();
}
private void pictureBox_Exit_MouseLeave(object sender, EventArgs e)
{
PageChange_MouseWheel = false;
}
#endregion
private void HistoryForm_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{//滑轮控制的事件
if (PageChange_MouseWheel)
{
int temp = - e.Delta / Math.Abs(e.Delta);
if (CurrentPage > 1 && CurrentPage < MaxPage)
CurrentPage += temp;
else if (MaxPage != 1)
{
if (CurrentPage == 1 && temp > 0)
CurrentPage += temp;
if (CurrentPage == MaxPage && temp < 0)
CurrentPage += temp;
}
label_Page.Text = CurrentPage.ToString();
label_Page.Location = new Point(this.Width / 2 - label_Page.Width / 2 - 14, label_Page.Location.Y);//居中
for (int i = 0; i < 5; i++)
{
int Line = N_History - (CurrentPage - 1) * 5 - i - 1;
for (int j = 0; j < 4; j++)
if (Line >= 0)
{
LabelMatrix[i, j].Text = HistoryRecord[Line, j + 1];
LabelMatrix[i, j].Location = new Point(ChartArrange_X[j] - LabelMatrix[i, j].Width / 2, ChartLine_Y[i] - LabelMatrix[i, j].Height / 2);
}
else LabelMatrix[i, j].Text = "";
if (Line >= 0) switch (HistoryRecord[Line, 0])
{
case "3": LabelMatrix[i, 1].ForeColor = Color.Black; break;
case "4": LabelMatrix[i, 1].ForeColor = Color.Purple; break;
case "5": LabelMatrix[i, 1].ForeColor = Color.Goldenrod; break;
}
}
}
}
}
}
对应设计器:
AskForLeave窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 原神UP角色抽卡模拟器
{
public partial class AskForLeave : Form
{
public AskForLeave()
{
InitializeComponent();
}
#region 使窗体可以移动的代码
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
#endregion
private void AskForLeave_Load(object sender, EventArgs e)
{
pictureBox_Cancel.BackColor = pictureBox_OK.BackColor = Color.FromArgb(0, 0, 0, 0);
panel_Cancel.Visible = panel_OK.Visible = false;
}
private void pictureBox_OK_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void pictureBox_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void pictureBox_Cancel_MouseEnter(object sender, EventArgs e)
{
panel_Cancel.Visible = true;
}
private void pictureBox_Cancel_MouseLeave(object sender, EventArgs e)
{
panel_Cancel.Visible = false;
}
private void pictureBox_OK_MouseEnter(object sender, EventArgs e)
{
panel_OK.Visible = true;
}
private void pictureBox_OK_MouseLeave(object sender, EventArgs e)
{
panel_OK.Visible = false;
}
private void AskForLeave_MouseMove(object sender, MouseEventArgs e)
{// 拖动窗体
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
this.Cursor = System.Windows.Forms.Cursors.Default;
}
}
}
对应设计器:
AboutForm窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
namespace 原神UP角色抽卡模拟器
{
public partial class AboutForm : Form
{
public AboutForm()
{
InitializeComponent();
}
#region 使窗体可以移动的代码
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
#endregion
Thread CurrentOperate = null;
const int Y_Start = 666, Y_Dest = 250;
Point P_Start = new Point(0, Y_Start), P_Dest = new Point(0, Y_Dest);
private void AboutForm_Load(object sender, EventArgs e)
{
label_More.BackColor =
pictureBox_Q_Author.BackColor =
pictureBox_Q_Software.BackColor =
pictureBox_Exit.BackColor =
pictureBox_Retract.BackColor =
Color.FromArgb(0, 0, 0, 0);
panel_More.Location = new Point(0,this.Height);
}
private void AboutForm_FormClosed(object sender, FormClosedEventArgs e)
{
}
private void AboutForm_FormClosing(object sender, FormClosingEventArgs e)
{
}
private void AboutForm_MouseMove(object sender, MouseEventArgs e)
{// 拖动窗体
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
this.Cursor = System.Windows.Forms.Cursors.Default;
}
private void pictureBox_Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void pictureBox_Q_Software_Click(object sender, EventArgs e)
{
if (CurrentOperate!=null)
{
CurrentOperate.Interrupt();
CurrentOperate = null;
}
CurrentOperate = new Thread(new ThreadStart(OpenMore));
CurrentOperate.Start();
label_More.Text = "点击以跳转到软件使用指南";
label_More.Location = new Point(panel_More.Width / 2 - label_More.Width / 2, 100);
}
private void pictureBox_Retract_Click(object sender, EventArgs e)
{
if (CurrentOperate != null)
{
CurrentOperate.Interrupt();
CurrentOperate = null;
}
CurrentOperate = new Thread(new ThreadStart(RetractMore));
CurrentOperate.Start();
}
private void pictureBox_Q_Author_Click(object sender, EventArgs e)
{
if (CurrentOperate != null)
{
CurrentOperate.Interrupt();
CurrentOperate = null;
}
CurrentOperate = new Thread(new ThreadStart(OpenMore));
CurrentOperate.Start();
label_More.Text = "点击以跳转到作者博客主页";
label_More.Location = new Point(panel_More.Width / 2 - label_More.Width / 2, 100);
}
private void pictureBox_AboutSoftware_Click(object sender, EventArgs e)
{//地址需要更改
Process.Start("https://sherrychou.blog.csdn.net/article/details/135026809");
this.Close();
}
private void pictureBox_AboutAuthor_Click(object sender, EventArgs e)
{
Process.Start("http://sherrychou.blog.csdn.net");
this.Close();
}
private void OpenMore()
{//打开底部“更多”页面的线程
for (int i = 1; i < 10; i++)
{
Invoke(new Action(() =>
{
panel_More.Location = new Point(0, Y_Start - i*45);
}));//跨线程操作
Thread.Sleep(25);
}
Invoke(new Action(() =>
{
panel_More.Location = P_Dest;
}));//跨线程操作
return;
}
private void RetractMore()
{//收起底部“更多”页面的线程
for (int i = 1; i < 10; i++)
{
Invoke(new Action(() =>
{
panel_More.Location = new Point(0, Y_Dest + i*20);
}));//跨线程操作
Thread.Sleep(20);
}
Invoke(new Action(() =>
{
panel_More.Location = P_Start;
}));//跨线程操作
return;
}
}
}
对应设计器:
全文:40994字