www.pudn.com > WM5.0forGIF.rar > Form1.cs


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.Drawing.Imaging; 
 
namespace gifTest 
{ 
    public partial class Form1 : Form 
    { 
        AnimateCtl animCtl = null;    //创建一个控件对象animCtl 
        public Form1() 
        { 
            InitializeComponent(); 
            //实例化控件 
            animCtl = new AnimateCtl(); 
            //从图像文件指定 Bitmap 
            animCtl.Bitmap = new Bitmap(Resource.GIF2); 
            //设置位置 
            animCtl.Location = new Point(0, 0); 
            //将控件添加到窗体 
            this.Controls.Add(animCtl); 
        } 
 
        private void Form1_KeyDown(object sender, KeyEventArgs e) 
        { 
            if ((e.KeyCode == System.Windows.Forms.Keys.Up)) 
            { 
                // Up 
            } 
            if ((e.KeyCode == System.Windows.Forms.Keys.Down)) 
            { 
                // Down 
            } 
            if ((e.KeyCode == System.Windows.Forms.Keys.Left)) 
            { 
                // Left 
                animCtl.StartAnimation(240, 200, -1);    //开始播放动画 
            } 
            if ((e.KeyCode == System.Windows.Forms.Keys.Right)) 
            { 
                // Right 
                animCtl.StopAnimation();    //停止播放动画 
            } 
            if ((e.KeyCode == System.Windows.Forms.Keys.Enter)) 
            { 
                // Enter 
                Application.Exit(); 
            } 
 
        } 
    } 
}