c# _抽奖_代码
程序员文章站
2022-07-12 12:51:30
...
抽奖小程序
随笔
年会马上就要到了,各个公司都在准备年会的一些事宜!
初始化奖池
//简单点,没有做递归查找图片
pictureList.Clear();
nameList.Clear();
try
{
DirectoryInfo folder = new DirectoryInfo(_ImagePath);
FileInfo[] fiArr1 = folder.GetFiles("*.jpg");
InitArrs(fiArr1);
FileInfo[] fiArr2 = folder.GetFiles("*.png");
InitArrs(fiArr2);
FileInfo[] fiArr3 = folder.GetFiles("*.bmp");
InitArrs(fiArr3);
if (null == nameList || nameList.Count < 1)
{
bError = true;
MessageBox.Show(_TipError);
return;
}
if (nameList.Count == 1)
{
bError = true;
MessageBox.Show(_TipOnlyOne);
return;
}
//初始化成功后默认显示第一个
this.picEmp.Image = this.pictureList[p1];
this.lblEmpName.Text = this.nameList[p1];
}
catch (Exception)
{
bError = true;
MessageBox.Show(_TipError);
return;
}
private void InitArrs(FileInfo[] fiArr1)
{
if (null != fiArr1 && fiArr1.Length > 0)
{
foreach (FileInfo file in fiArr1)
{
nameList.Add(file.Name.Substring(0, file.Name.IndexOf('.')));
pictureList.Add(Image.FromFile(file.FullName));
}
}
}
抽奖
if (bError)
{
return;
}
this.timer1.Start();
this.btnStart.Enabled = false;
this.btnStop.Enabled = true;
this.lblResult.Text = null;
this.lblResult.Hide();
this.lblWait.Text = titleWait;
this.lblWait.Show();
private void timer1_Tick(object sender, EventArgs e)
{
p1++;
if (p1 >= pictureList.Count)
{
p1 = 0;
}
this.picEmp.Image = pictureList[p1];
this.lblEmpName.Text = nameList[p1];
}
主要的代码已上传
有需要,想要学习的请联系!一起学习哈!
关注该公众号!回复 朋友 即可获得!
下一篇: javascript礼品抽奖