zoukankan      html  css  js  c++  java
  • winform 显示动态图片 Gif

    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);

             // http://www.cnblogs.com/sosoft/

            }

            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)

            {

            }

        }

    }

    。net交流
  • 相关阅读:
    ASCII对应码表-键值(完整版)
    node.js中使用路由方法
    关于vscode自动跳转回车的解决方法(关闭vscode自动保存功能;可能和其他插件有冲突)
    js中 !==和 !=的区别是什么
    spring 请求参数和路径变量
    PowerShell因为在此系统中禁止执行脚本解决方法
    SQL server 2008数据库的备份与还原(亲测,效果良好)注意采用单用户模式呀
    webpack-dev-server提示css模块解析失败,但已经装了css-loader
    webpack集成vue单文件模式的很多坑(研究了1个星期)
    npm全局模块卸载及默认安装目录修改方法
  • 原文地址:https://www.cnblogs.com/hcyblogs/p/4636122.html
Copyright © 2011-2022 走看看