图片切换(timer控件与ImagesList结合使用)
- 摘要:privatevoidForm3_Load(objectsender,EventArgse){//打开窗体的时候显示第一张图片this.pictureBox1.Image=this.imageList1.Images[0];//启动timer控件this.timer1.Start();}//计数器privateintcurrIndex=0;privateboolflag=true;//开关privatevoidtimer1_Tick(objectsender,EventArgse){if
- 标签:使用 list 图片 结合 控件
- private void Form3_Load(object sender, EventArgs e)
- {
- //打开窗体的时候显示第一张图片
- this.pictureBox1.Image = this.imageList1.Images[0];
- //启动timer控件
- this.timer1.Start();
- }
- //计数器
- private int currIndex = 0;
- private bool flag = true;//开关
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (flag)
- {
- //判断是否为第一张
- //不是第一张
- if (currIndex > 0)
- //显示上一张图片
- currIndex--;
- else
- //是第一张
- flag = false;
- }
- else
- {
- //判断是否为第一张
- //不是最后一张
- if (currIndex < this.imageList1.Images.Count - 1)
- //显示下下一张图片
- currIndex++;
- else//是最后一张
- flag = true;
- }
- this.pictureBox1.Image = this.imageList1.Images[currIndex];
- }
- private bool flag1 = true;
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- if (flag1)
- {
- //停止
- timer1.Stop();
- flag1 = false;
- }
- else
- {
- //启动
- timer1.Start();
- flag1 = true;
- }
- }