Click here to Skip to main content
Click here to Skip to main content

FormAnimations

, 25 Apr 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
An article on Windows Form animations, movements.

Some of the things that can be done

Introduction

Have you always wanted to implement some window animations with your program's GUI's? If the answer is Yes, but you:

  1. Felt lazy and did not want to waste your time,
  2. Thought "let someone else do it for me",
  3. Did not know how or where to start.

Then worry no more, here's the code and/or DLL to do so. You will be able to make your form fly from Left to Right, Right to Left, Top to Bottom, Bottom to Top of the screen, as well as to FadeIn, FadeOut, Grow, Shrink, Shake and Move it, just to mention some of the fun and interesting things you can develop with a little pinch of imagination.

Sounds interesting, right?

Some uses

I think FormAnimations will be of great help if you want your form to do some cool tricks, for example:

  • You could use it when your program's opened or closed or to respond to any other event you want.
  • I've also used it for a Felix the Cat companion I'm developing which I'll be releasing sometime soon.
  • You can use it like a screen saver, or screen bouncing or anything you can come up with, your screen is the limit.

Using the code

Basically, all the functionality is provided through FormAnim.dll, which is very simple to use. It contains two classes, FormAnimations and AnimationPreparer and one enum called Constantes.

FormAnimations is the core, this is where all the available methods are; AnimationPreparer is meant to help the user when deploying the animations and the Constantes enumeration contains the movements available as well some predefined screen positions where the main form can be moved to.

You can take a look at the code and even modify any of the algorithms to fit your needs, nevertheless it would be a nice gesture if you let me know of such activities or any improvements.

Points of Interest

Did I learn anything interesting/fun/annoying while writing the code?

As a matter of fact, I did, but first and before I start complaining, I would like to point out that this code is form-oriented but it can easily be modified to move other controls such as buttons, textboxes, labels or anything that derivates from the System.Windows.Forms.Control class.

Now, the interesting and curious but also annoying daemons I found while I was working in this project and another companion project are:

  1. Apparently, .NET still has several issues with some graphics and images, just to start, MSDN states that if a screen's resolution depth is in true color or has more than 24-bit intensity colors, it might not display transparency. This poses a problem because some people do work with this kind of resolutions and they won't be able to see your form the way you designed it, but the weirdest thing is that some controls (like textboxes) do get transparent even if the resolution has more than 24-bit intensity colors.
  2. .NET has problems with refreshing the form and its layout controls, I had to do Form.Refresh(); or Form.Update(); (by the way the difference between both is not clearly stated) every time I did something to the Form. If I didn't, it just would not show the Form's controls while the animation was running.
  3. I tried to get two or more different animations running at the same time, but most of the combinations I tried didn't work, this doesn't mean that it's not possible or that the ones you come up with will have the same faith, therefore I encourage you to try any of them to see if they work. Some of the combinations that worked for me are shown in the code, they provide an example on how you could try yours.

    But why didn't they work is the question... while some were hard to synchronize so that the effect looked smooth or that both Threads would finish around the same time, others behaved strangely, and for that behavior, I blame .NET. I left the combined animation Left2RightGrowVertical for you to try. The effect is cool but useless, the form moves Left to Right while it Vertically Grows, the problem is that the form's controls also move Left to Right while a part of the animation takes place.

  4. The FormAnimations can be used with any form even non rectangular shaped forms, but I won't be responsible for any strange performance. I had a hard time when working with them, they slow down the application, they don't show icons, they don't have full functionality, the refresh is not well done and .NET doesn't respect the images 'raw' formats (with this I mean that if you use a GIF or PNG with transparent color as a your Form's background, .NET wont' care, forget animated GIFs, and imagelists. I added some animated GIFs to an ImageList and they won't show animated when assigned to a Picturebox.Image.

I could go on with other minor and maybe not so minor details I came across but I will stop here and let you try and discover for yourself the good or bad magical wonders of C# WinForms programming.

Ah, in case you wondered: I worked with a Windows XP powered by ATI video card and with a Windows 2000 Professional Intel Extreme Graphics card, and I had to deal with the issues described above.

I must make clear that these are my and only my impressions, and they may differ from any of yours.

History

FormAnimations is my second article. Even though I think some improvements can be made in certain animations, I don't think I will be making any in the near future. But as usual, any comments, critics, questions, mistakes or anything are always welcomed.

License

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

Share

About the Author

Thoughthopper
Web Developer
Canada Canada
Althought i'm a Electronic Engineering, my stong side is IT.
 
I've developped code in different languages:
Assembly, C, Java, HTML, Javascript, Perl/CGI, VB6, and C#, in which i've been working latetly.
 
I'm also keen on Security and Cryptography topics, as well as on Multimedia Technologies.

Comments and Discussions

 
Generalgood jobs Pinmembersilas_yao26-Apr-05 6:14 
thx for this useful function for me. I'm a lazy man.
Smile | :)
 
silas
MCSE 1999

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 26 Apr 2005
Article Copyright 2005 by Thoughthopper
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid