[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Display animated GIFs and change them at run time in C#

display animated GIFs

You can display animated GIFs by setting the Image property of a Button, PictureBox, Label, or other control to the GIF file. (If you display one in a Form's BackgroundImage property, you don't get the animation.)

There are a couple of ways to change GIFs at runtime.

First, you can add the GIF as a resource. Open the Project menu and select Properties at the bottom. On the Resources tab, open the Add Resource dropdown and select Add Existing File. Browse to the GIF and click Open.

Now you can use the GIF resource as in:

picGif.Image = howto_display_animated_gif.Properties.Resources.puppy;

You can also load GIFs from a file as in the following code.

lblGif.Image = Image.FromFile(filename + "alien.gif");

This program uses resources to change GIFs when you click on its Button or PictureBox. It loads GIFs from files when you click its Label.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.