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);
http://www.cnblogs.com/sosoft/
}
protected override void OnPaint (PaintEventArgs e)
{
Base. OnPaint (e);
if (m_imgimage! = null)
{
UpdateImage ();
E.graphics.drawimage (M_imgimage, new Rectangle (+, M_imgimage.width, m_imgimage.height));
}
}
protected override void OnLoad (EventArgs e)
{
Base. OnLoad (e);
M_imgimage = Image.FromFile ("1.gif"); Loading a GIF image for testing
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 Show Animated Gif