WinForm Show Animated Gif

Source: Internet
Author: User

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 (+, M_imgimage.width, m_imgimage.height));

}

}

protected override void OnLoad (EventArgs e)

{

Base. OnLoad (e);

M_imgimage = Image.FromFile ("1.gif"); Loading a GIF image for testing

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)

{

}

}

}

WinForm Show Animated Gif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.