选择人员参与游戏的小程序
每次听潘加宇老师的讲课的时候,对他制作的选择人和奖品的小创意钦佩不已,这种选择的好处很多,就不说了。
今日偷师学艺,也开发了一个超小了程序,来实现此功能。够用就好了,潘老师千万别追究版权问题。
源代码如下 :
using System;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SelectOne
{
public partial class frmChoseOne : Form
{
private string[] personList ;
private Boolean blnChosePersonId = true;
private int currentPerson = 0;
private int itemInPersonList = 0;
private static string[] giftList;
private Boolean blnChoseGiftId = true;
private int currentGift = 0;
private int itemInGiftList = 0;
public frmChoseOne()
{
InitializeComponent();
InitialList();
}
private void InitialList()
{
string temppersonList = ConfigurationManager.AppSettings["personList"];
personList = temppersonList.Split(';');
itemInPersonList = personList.Length - 1;
string tempgiftList = ConfigurationManager.AppSettings["giftList"];
giftList = tempgiftList.Split(';');
itemInGiftList = giftList.Length - 1;
}
private void btnChosePerson_Click(object sender, EventArgs e)
{
if (blnChosePersonId)
{
tmrChosePerson.Start();
btnChosePerson.Text = "停止";
}
else
{
tmrChosePerson.Stop();
btnChosePerson.Text = "选人";
}
blnChosePersonId = !blnChosePersonId;
}
private void tmrChosePerson_Tick(object sender, EventArgs e)
{
currentPerson++;
if (currentPerson > itemInPersonList)
{
currentPerson = 0;
}
lblDisplayPersonName.Text = personList[currentPerson];
}
private void tmrChoseGift_Tick(object sender, EventArgs e)
{
currentGift++;
if (currentGift > itemInGiftList)
{
currentGift = 0;
}
lblChoseGift.Text = giftList[currentGift];
}
private void btnChoseGift_Click(object sender, EventArgs e)
{
if (blnChoseGiftId)
{
tmrChoseGift.Start();
btnChoseGift.Text = "停止";
}
else
{
tmrChoseGift.Stop();
btnChoseGift.Text = "选礼物";
}
blnChoseGiftId = !blnChoseGiftId;
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<clear />
<add key ="personList" value="A;B;C;D" />
<add key ="giftList" value="蜂蜜茶;蛋挞;蜂蜜茶;蛋挞;蜂蜜茶;蛋挞;蜂蜜茶;蛋挞;蜂蜜茶;蛋挞;拿铁;蛋挞;" />
</appSettings>
</configuration>