c# winform 一定时间内循环播放图片 |
您所在的位置:网站首页 › ipad如何滚动播放图片 › c# winform 一定时间内循环播放图片 |
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 办公设备维修网 版权所有 豫ICP备15022753号-3 |