Click here to Skip to main content
15,881,882 members
Articles / Multimedia / GDI+
Article

Custom Status Animation with VB.NET

Rate me:
Please Sign up or sign in to vote.
3.88/5 (21 votes)
7 Oct 2008CPOL2 min read 71.2K   2.7K   52   19
Provide eye-candy to your users with custom animations
Image 1

Introduction

Remember when something happening in 5 seconds was really quick? Today if something in your application takes more than 5 seconds, your users think the application is locked. Sure I'm exaggerating, but wouldn't it be nice to display something 'eye-catching' while your users are waiting for a long running process to complete? This component uses GDI to draw a series of PNG files onto a form, along with an updatable header and message. Very simple concept, but something that will give your application a professional look. It runs on its own thread and is completely thread-safe, so you can continue with what you are doing while the animation is occurring.

Enjoy!

Using the Code

You can use one of the predefined AnimationData objects, referenced by a corresponding enumeration, or you can create a custom AnimationData object outside of the component and pass it in. I prefer using PNG files for the individual frames (images) of the animation as they support alpha-blending.

CancelClicked Event

When you allow the cancel link to be shown (using the AllowCancel property), you can intercept the cancel and provide a dialog with the CancelClicked event to ask if you really want to cancel the animation. After the user clicks yes, you can do whatever is necessary in the application to stop the process, then set e.Cancel = True in the eventargs. This will be passed back to the component to stop the animation. If you pass back False (e.Cancel = False), then the animation will continue.

AnimationData.FromSingleImage Method

You can create an AnimationData object from a single image that includes all of the frames of the animation. To do this, add the image to your project and call the AnimationData.FromSingleImage method. Tell the method how many frames the animation contains and it will split the single image up into the individual frames and populate the images list. Specifying a transparency color will make that color transparent in the image.  When the method returns, set the AnimationData properties appropriately for your needs and call the Show method.

History

  • 26th September, 2008: Initial post
  • 29th September, 2008: Added CancelClicked event description
  • 3rd October, 2008: Updated code to fix fast Cancel
  • 7th October, 2008: Added AnimationData.FromSingleImage method description

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
Visual Basic Developer since version 1.0
Java web developer
Currently developing in vb and c#

Comments and Discussions

 
QuestionConverting solution Pin
Mike 200528-Oct-13 2:53
Mike 200528-Oct-13 2:53 
Very nice. Thank you. Big Grin | :-D

I use VS2010.
I had to convert your code because it was created on an earlier version, but that was no problem.
When I tried to view Form1 I got an error - relating to the conversion.
The solution was simple.
Firstly I rebuilt CMAnimation.
Then I rebuilt Tester.
Then everything was fine.
This info might be useful to others?
QuestionWhy the form? Pin
Elfman_NE22-Apr-10 10:21
Elfman_NE22-Apr-10 10:21 
GeneralMessage to user comes up behind animation Pin
yet another programmer23-Sep-09 4:55
yet another programmer23-Sep-09 4:55 
GeneralHelp Pin
fuxiurong_200120-Oct-08 22:44
fuxiurong_200120-Oct-08 22:44 
AnswerRe: Help Pin
Greg Osborne21-Oct-08 2:42
Greg Osborne21-Oct-08 2:42 
GeneralCancel not working Pin
PSU Steve3-Oct-08 4:53
professionalPSU Steve3-Oct-08 4:53 
AnswerRe: Cancel not working Pin
Greg Osborne3-Oct-08 5:21
Greg Osborne3-Oct-08 5:21 
GeneralRe: Cancel not working Pin
PSU Steve3-Oct-08 6:31
professionalPSU Steve3-Oct-08 6:31 
AnswerRe: Cancel not working Pin
Greg Osborne3-Oct-08 6:51
Greg Osborne3-Oct-08 6:51 
GeneralRe: Cancel not working Pin
PSU Steve3-Oct-08 7:00
professionalPSU Steve3-Oct-08 7:00 
QuestionMyClass. versus Me. Pin
richardw4829-Sep-08 7:06
richardw4829-Sep-08 7:06 
AnswerRe: MyClass. versus Me. Pin
Greg Osborne29-Sep-08 7:25
Greg Osborne29-Sep-08 7:25 
GeneralRe: MyClass. versus Me. Pin
Greg Osborne29-Sep-08 7:32
Greg Osborne29-Sep-08 7:32 
GeneralRe: MyClass. versus Me. Pin
richardw4829-Sep-08 7:38
richardw4829-Sep-08 7:38 
QuestionAny C# Code ? Pin
Pankaj Nikam29-Sep-08 5:07
professionalPankaj Nikam29-Sep-08 5:07 
AnswerRe: Any C# Code ? Pin
Greg Osborne29-Sep-08 5:41
Greg Osborne29-Sep-08 5:41 
GeneralRe: Any C# Code ? Pin
Pankaj Nikam29-Sep-08 6:15
professionalPankaj Nikam29-Sep-08 6:15 
GeneralWell Done Greg Pin
DumpsterJuice29-Sep-08 2:30
DumpsterJuice29-Sep-08 2:30 
GeneralVery Nice Pin
sam.hill26-Sep-08 17:27
sam.hill26-Sep-08 17:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.