using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
System.Data;
using
System.Diagnostics;
namespace
Graphics
...
{
/**//// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private Image m_imgImage = null;
private EventHandler m_evthdlAnimator = null;
public Form1()
...{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint,true);
this.SetStyle(ControlStyles.DoubleBuffer,true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
//
// TODO: Add any constructor code after InitializeComponent call
//
m_evthdlAnimator = new EventHandler(OnImageAnimate);
Debug.Assert(m_evthdlAnimator != null);
}

/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null) 
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void OnPaint(PaintEventArgs e)
...{
base.OnPaint (e);
if (m_imgImage != null)
...{
UpdateImage();
// 绘制图片的当前帧
e.Graphics.DrawImage(m_imgImage,new Rectangle(10,10,m_imgImage.Width,m_imgImage.Height));
}
}
protected override void OnLoad(EventArgs e)
...{
base.OnLoad (e);
m_imgImage = Image.FromFile("10.gif"); // 加载测试用的Gif图片
BeginAnimate();
}

Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
...{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Closed += new System.EventHandler(this.Form1_Closed);
}
#endregion

/**//// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() 
...{
Application.Run(new Form1());
}
private void Form1_Closed(object sender, System.EventArgs e)
...{
if (m_imgImage != null)
...{
StopAnimate();
m_imgImage = null;
}
}

functions of animator image#region functions of animator image
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);
}
}

/**//// <summary>
/// 动画图片帧变化的时间触发,这个事件并非在主线程中触发
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnImageAnimate(Object sender,EventArgs e)
...{
this.Invalidate();
}
#endregion // End of functions of animator image
}
}
this.SetStyle(ControlStyles.DoubleBuffer,true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
6512



被折叠的 条评论
为什么被折叠?



