复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.linq;
using System.Text;
using System.windows.Forms;
using System.Diagnostics;
namespace DysncPicTest
{
public partial class Form1 : Form
{
private Image m_imgImage = null;
private EventHandler m_evthdlAnimator = null;
public Form1()
{
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint,true);
this.SetStyle(ControlStyles.DoubleBuffer,true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
m_evthdlAnimator = new EventHandler(OnImageAnimate);
DeBUG.Assert(m_evthdlAnimator != null);
}
protected overrIDe voID OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (m_imgImage != null)
{
UpdateImage();
e.Graphics.DrawImage(m_imgImage,new Rectangle(100,100,m_imgImage.WIDth,m_imgImage.Height));
}
}
protected overrIDe voID OnLoad(EventArgs e)
{
base.OnLoad(e);
m_imgImage = Image.Fromfile("1.gif"); // 加载测试用的gif图片
BeginAnimate();
}
private voID Form1_FormClosing(object sender,FormClosingEventArgs e)
{
if (m_imgImage != null)
{
StopAnimate();
m_imgImage = null;
}
}
private voID BeginAnimate()
{
if (m_imgImage == null)
return;
if (ImageAnimator.CanAnimate(m_imgImage))
{
ImageAnimator.Animate(m_imgImage,m_evthdlAnimator);
}
}
private voID StopAnimate()
{
if (m_imgImage == null)
return;
if (ImageAnimator.CanAnimate(m_imgImage))
{
ImageAnimator.StopAnimate(m_imgImage,m_evthdlAnimator);
}
}
private voID UpdateImage()
{
if (m_imgImage == null)
return;
if (ImageAnimator.CanAnimate(m_imgImage))
{
ImageAnimator.UpdateFrames(m_imgImage);
}
}
private voID OnImageAnimate(Object sender,EventArgs e)
{
this.InvalIDate();
}
private voID Form1_Load(object sender,EventArgs e)
{
}
}
}
以上是内存溢出为你收集整理的Winform 显示Gif图片的实例代码全部内容,希望文章能够帮你解决Winform 显示Gif图片的实例代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)