zoukankan      html  css  js  c++  java
  • Winform 显示Gif图片

    本文章是引用博客园——brave作者的,非常好用!!!保存下来,以备不时之需!

     

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

            }
        }
    }

  • 相关阅读:
    Openshift与Kubernetes的区别
    chrome显示正在等待可用的套接字如何解决
    wordpress上传图片附件时把绝对地址修改成相对地址
    flashfxp传输代码变形如何解决
    wordpress禁用模板编辑功能
    nginx设置Expires启用浏览器缓存Leverage browser caching
    如何设置ExpiresDefault启用浏览器缓存Leverage browser caching
    国外常用社交分享代码(纯代码无需插件)
    python识别网站所用技术
    nginx设置http 301重定向到https
  • 原文地址:https://www.cnblogs.com/hbliu_ren/p/1297836.html
Copyright © 2011-2022 走看看