1.在Visual Studio中,首先新建一个windows窗体项目
2.Form1.cs[设计]窗口中,从工具箱拖拽pictureBox,button1,button2,imageList,timer到窗口上
3.设置imagelist属性:先设置ColorDepth=Depth32Bit,然后设置images会打开一个图片添加窗口,单击添加按钮加图片(就是抽奖时要循环的多张图片)
4.然后双击timer控件,双击button1控件,双击button2控件
5.然后在设计窗口点选这个窗口按F7
7.然后对照显示的代码,把下面三个事件的中缺少的代码敲进去,ok搞定
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
}
int index = 0;
private void timer1_Tick(object sender, EventArgs e)
{
//当索引不超过图片集的图片个数时,把图片集中的图片一张一张赋给pictureBox控件的image属性
if (index<imageList1.Images.Count)
{
pictureBox1.Image = imageList1.Images[index];
index++;
}
else
{
index = 0;
}
}