winform C# 顯示動畫——這裡用GIF格式——來自MSDN
阿新 • • 發佈:2019-02-18
下面的程式碼來自MSDN的示例程式碼
using System; using System.Drawing; using System.Windows.Forms; public class animateImage : Form { //Create a Bitmpap Object. Bitmap animatedImage = new Bitmap("SampleAnimation.gif"); bool currentlyAnimating = false; //This method begins the animation. public void AnimateImage() { if (!currentlyAnimating) { //Begin the animation only once. ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged)); currentlyAnimating = true; } } private void OnFrameChanged(object o, EventArgs e) { //Force a call to the Paint event handler. this.Invalidate(); } protected override void OnPaint(PaintEventArgs e) { //Begin the animation. AnimateImage(); //Get the next frame ready for rendering. ImageAnimator.UpdateFrames(); //Draw the next frame in the animation. e.Graphics.DrawImage(this.animatedImage, new Point(0, 0)); } public static void Main() { Application.Run(new animateImage()); } }
MSDN連線:http://msdn.microsoft.com/zh-cn/library/7zcfh1k4.aspx
自己記錄下來,不是抄襲,就是不知道是不是原創,留著以後用。