Advertisement
f0rkB0mb

Aniomated GIFs in WinForms

Apr 15th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace AnimGIF
  11. {
  12.     /**
  13.         Please include a animated gif into the debug/release folder
  14.         **/
  15.     public partial class Form1 : Form
  16.     {
  17.         private Bitmap myGif = null;
  18.         private string nameOfMyGIF = "1.gif";
  19.  
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void Form1_Load(object sender, EventArgs e)
  26.         {
  27.             myGif = (Bitmap)Image.FromFile(Application.StartupPath + @"\" + nameOfMyGIF);
  28.             if (ImageAnimator.CanAnimate(myGif))
  29.                 ImageAnimator.Animate(myGif, this.OnNextFrameUpdateForm); //a self created event-hdlr.
  30.             else
  31.             {
  32.                 MessageBox.Show("THIS IMAGE COULDN'T BE ANIMATED!");
  33.                 return;
  34.             }
  35.             SetStyle(ControlStyles.UserPaint, true);
  36.             SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  37.             SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  38.         }
  39.  
  40.         private void OnNextFrameUpdateForm(object sender, EventArgs e)
  41.         {
  42.             this.Invalidate();
  43.         }
  44.  
  45.         protected override void OnPaint(PaintEventArgs e)
  46.         {
  47.             e.Graphics.DrawImage(myGif, 10, 10);
  48.             ImageAnimator.UpdateFrames();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement