<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Animated Gif</Title>
      <Shortcut>AnimatedGif</Shortcut>
      <Description>Animated Gif [C#]</Description>
      <Author>Robert Wagner</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=0df7a39c-ec51-4850-ae7a-160e108d0b3a</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[private bool isAnimating = false;
private void Button1_Click( object sender, System.EventArgs e) 
{
    // Stop animation
    System.Drawing.ImageAnimator.StopAnimate( 
        this.PictureBox1.Image, this.OnFrameChanged);
}
private void Button2_Click( object sender, System.EventArgs e) 
{
	System.Drawing.ImageAnimator.Animate( 
        this.PictureBox1.Image, this.OnFrameChanged);
    isAnimating = false;
}
private void OnFrameChanged( object sender, EventArgs e)
{
    // Force  call to the Paint event handler
    this.Invalidate();
}
private void AnimateImage()
{
    if( !isAnimating )
	{
        // Begin animation only once.
        System.Drawing.ImageAnimator.Animate(this.PictureBox1.Image, 
            this.OnFrameChanged);
        isAnimating = true;
    }
}
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.PictureBox1.Image, 
		this.PictureBox1.Location.X, this.PictureBox1.Location.Y);
}]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>