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.
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.
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
e.Cancel = False), then the animation will continue.
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
- 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