c# winform 一定时间内循环播放图片 您所在的位置:网站首页 windows图片自动播放速度 c# winform 一定时间内循环播放图片

c# winform 一定时间内循环播放图片

2024-02-17 20:01| 来源: 网络整理| 查看: 265

c# winform 一定时间内循环播放图片

用winform开发项目中,想要在界面实现一个gif的效果,于是想到了用循环播放图片的方法来实现。因为有时间要求,于是想到了用c# 的timer模块实现。

方法1使用 System.Timers.Timer()类实现,代码如下:

timer= new System.Timers.Timer(); timer.Interval = 1000/curFrameRate; int j = 0; timer.Elapsed += delegate { j++; if (j == gifPicsPath.Count - 1) { j = 0; } play_pics(gifPicsPath, j); }; timer.AutoReset = true; timer.Start(); private void play_pics(List tmpPicsPath,int j) { Image image = Image.FromFile(tmpPicsPath[j]); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Image = image; }

方法2 是使用Winform自带的挂件 timer,代码如下:

timer1 = new System.Windows.Forms.Timer(); timer1.Interval = 1000 / curFrameRate; timer1.Tick += new EventHandler(timer1_Tick); timer1.Enabled = false; void timer1_Tick(object sender,EventArgs e) { pictureBox1.Image = Image.FromFile(gifPicsPath[imageIndex]); imageIndex++; if (imageIndex > gifPicsPath.Count - 1) imageIndex = 0; }

两种方法都比较简单,如果大家有更好的实现方法,欢迎在评论区讨论



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有