• 【Winform 动图】winform窗体显示动图


    源地址忘记了

    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);
            }
    
            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                if (m_imgImage != null)
                {
                    UpdateImage();
                    e.Graphics.DrawImage(m_imgImage, new Rectangle(100, 100, m_imgImage.Width, m_imgImage.Height));
                }
            }
    
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                m_imgImage = Image.FromFile("1.gif"); // 加载测试用的Gif图片
                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)
            {
    
            }
        }
    }        

  • 相关阅读:
    matlab安装YaHei Consolas Hybrid字体
    Matlab各种拟合
    正态分布
    JQuery插件:遮罩+数据加载中。。。(特点:遮你想遮,罩你想罩)
    【调侃】IOC前世今生
    使用jquery的 uploadify,在谷歌浏览器上总会崩溃的解决方法
    源代码管理工具TFS2013安装与使用
    C# 给枚举定义DescriptionAttribute,把枚举转换为键值对
    Bootstrap 中文官网
    时间 时间戳 转换
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12539181.html
Copyright © 2020-2023  润新知