[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

How can I load an animated gif without using a control?

Hi guys,
I'm working with windows form in .net 2k5. I want to load an animated gif without using any control such as PictureBox. Is there any way re-drawing it?
0
nhagiaubungbu
Asked:
nhagiaubungbu
  • 2
1 Solution
 
vo1dCommented:
where do you wanna draw it?on a form? on a control?
0
 
nhagiaubungbuAuthor Commented:
On a form :)
0
 
vo1dCommented:
here is an example which comes from the msdn:

using System;
using System.Drawing;
using System.Windows.Forms;

public class animateImage : Form
{
                     
    //Create a Bitmpap Object.
    Bitmap animatedImage = new Bitmap("SampleAnimation.gif");
    bool currentlyAnimating = false;
                     
    //This method begins the animation.
    public void AnimateImage()
    {
        if (!currentlyAnimating)
        {
                     
            //Begin the animation only once.
            ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged));
            currentlyAnimating = true;
        }
    }

    private void OnFrameChanged(object o, EventArgs e)
    {
                     
        //Force a call to the Paint event handler.
        this.Invalidate();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
                     
        //Begin the animation.
        AnimateImage();
                     
        //Get the next frame ready for rendering.
        ImageAnimator.UpdateFrames();
                     
        //Draw the next frame in the animation.
        e.Graphics.DrawImage(this.animatedImage, new Point(0, 0));
    }

    public static void Main()
    {
        Application.Run(new animateImage());
    }
}

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now