form1.cs

来自「介于在网上没有相关的完整实例可供参考」· CS 代码 · 共 56 行

CS
56
字号
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();
            }

        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?