C# 简易图片抽奖器的实现

1.在Visual Studio 2010中,首先新建一个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;
            }
        }


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值