Click here to Skip to main content
6,822,613 members and growing! (20,162 online)
Email Password   helpLost your password?
Multimedia » GDI+ » General     Intermediate License: The Code Project Open License (CPOL)

Custom Status Animation with VB.NET

By Greg Osborne

Provide eye-candy to your users with custom animations
VB8.0Win2K, WinXP, Win2003, Vista, GDI+, VS2005, Dev, Design
Posted:26 Sep 2008
Updated:7 Oct 2008
Views:17,584
Bookmarked:39 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
19 votes for this article.
Popularity: 4.86 Rating: 3.80 out of 5
4 votes, 21.1%
1
1 vote, 5.3%
2

3
1 vote, 5.3%
4
13 votes, 68.4%
5

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)

About the Author

Greg Osborne


Member
Visual Basic Developer since version 1.0
Occupation: Software Developer (Senior)
Company: Iowa Foundation for Medical Care
Location: United States United States

Other popular GDI+ articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
GeneralMessage to user comes up behind animation Pinmemberyet another programmer5:55 23 Sep '09  
GeneralHelp Pinmemberfuxiurong_200123:44 20 Oct '08  
AnswerRe: Help PinmemberGreg Osborne3:42 21 Oct '08  
GeneralCancel not working PinmemberPSU Steve5:53 3 Oct '08  
AnswerRe: Cancel not working PinmemberGreg Osborne6:21 3 Oct '08  
GeneralRe: Cancel not working PinmemberPSU Steve7:31 3 Oct '08  
AnswerRe: Cancel not working PinmemberGreg Osborne7:51 3 Oct '08  
GeneralRe: Cancel not working PinmemberPSU Steve8:00 3 Oct '08  
QuestionMyClass. versus Me. PinmemberRVW8:06 29 Sep '08  
AnswerRe: MyClass. versus Me. PinmemberGreg Osborne8:25 29 Sep '08  
GeneralRe: MyClass. versus Me. PinmemberGreg Osborne8:32 29 Sep '08  
GeneralRe: MyClass. versus Me. PinmemberRVW8:38 29 Sep '08  
GeneralAny C# Code ? PinmemberPankajkumar Nikam6:07 29 Sep '08  
GeneralRe: Any C# Code ? PinmemberGreg Osborne6:41 29 Sep '08  
GeneralRe: Any C# Code ? PinmemberPankajkumar Nikam7:15 29 Sep '08  
GeneralWell Done Greg PinmemberDumpsterJuice3:30 29 Sep '08  
GeneralVery Nice Pinmembersam.hill18:27 26 Sep '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 7 Oct 2008
Editor: Deeksha Shenoy
Copyright 2008 by Greg Osborne
Everything else Copyright © CodeProject, 1999-2010
Web21 | Advertise on the Code Project