Click here to Skip to main content
15,669,697 members
Articles / Multimedia / GDI+
Posted 19 Feb 2013


224 bookmarked

Animator for WinForms

Rate me:
Please Sign up or sign in to vote.
4.96/5 (185 votes)
22 Feb 2013LGPL34 min read
The component allows you to animate any controls on your WinForms.
Image 1   Image 2
Image 3


Can we make our WinForms application was animated, like WPF? Yep, of course we can!
The component Animator allows you to animate any controls on your WinForms.

How it works

Animator creates a temporary control DoubleBitmap over the target control. DoubleBitmap contains two images. First image is snapshot of background of the form, exclude target control. Second image contains snapshot of target control.

Image 4

Then animator periodically transforms top image of DoubleBitmap. As result – we get animated fake of target control.

Each transformation has some dependence on the current time. And Animator changes time and call transformation for new animation frame.

The Animator supports two kinds of transforms - linear transforms (scaling, shifting, rotating) and non-linear transforms (distortions, skews, etc). Also it can change transparency of animated bitmap.

Linear transformations are performed using matrix transformations of GDI+.
Example of the transformation Rotate:

public static void DoRotate(TransfromNeededEventArg e, Animation animation)
    var rect = e.ClientRectangle;
    var center = new PointF(rect.Width / 2, rect.Height / 2);
    e.Matrix.Translate(center.X, center.Y);
    if (e.CurrentTime > animation.RotateLimit)
        e.Matrix.Rotate(360 * (e.CurrentTime - animation.RotateLimit) * animation.RotateCoeff);
    e.Matrix.Translate(-center.X, -center.Y);

Nonlinear transformations are little harder. First, it creates an array of pixels. And then there is a conversion each pixel in cycle. The Animator can change coordinates of the pixel, it's color and transparency. Below is an example of the transformation:

public static void DoBlind(NonLinearTransfromNeededEventArg e, Animation animation)
    if (animation.BlindCoeff == PointF.Empty)
    var pixels = e.Pixels;
    var sx = e.ClientRectangle.Width;
    var sy = e.ClientRectangle.Height;
    var s = e.Stride;
    var kx = animation.BlindCoeff.X;
    var ky = animation.BlindCoeff.Y;
    var a = (int)((sx * kx + sy * ky) * (1 - e.CurrentTime));
    for (int x = 0; x < sx; x++)
        for (int y = 0; y < sy; y++)
            int i = y * s + x * bytesPerPixel;
            if (x * kx + y * ky >= a)
                pixels[i + 3] = (byte)0;

The Animator creates DoubleBitmap with correct z-order. So, if some controls were under target control, then they will be under DoubleBitmap control. Similarly – controls above target control:

Image 5

How to use

Simplest way to use Animator: dragging the Animator component onto your form.
To start animation – call method Animator.Show(targetControl) from your code.

Take to attention: the target control must be hidden (visible==false) before calling Show method. Otherwise animation will not take effect.

Similarly, you can hide the control using the method Animator.Hide(targetControl).

The Animator allows you to make animated changing of your visible control. Before updating you need to call Animator.BeginUpdate(targetControl), then update your control, and finally to call Animator.EndUpdate(targetControl). For example:

animator.BeginUpdateSync(dataGridView1, true);
dataGridView1[col, row].Value = newValue;

As result – the control will change its view with animation.

Animator has several built-in types of animation. It's Rotate, Scale, Leaf, Mosaic, Particles, Blind, etc. You can set built-in animation by property AnimationType.

In addition, Animator allows you to fine-tune the animation, as well as create custom animation.
For adjusting you can use property DefaultAnimation. Below described all properties of Animation class:

  • PointF SlideCoeff - Set (1,0) or (0,1) to slider effect.
  • float RotateCoeff - Adjusts rotation angle.
  • float RotateLimit - Parameter defines time of end of rotation
  • PointF ScaleCoeff - Adjusts horizontal and vertical scaling
  • float LeafCoeff - Set 1 to "leaf" effect
  • PointF MosaicCoeff - Adjusts deviation of mosaic
  • int MosaicSize - Mosaic square size (in pixels)
  • PointF MosaicShift - Shift of mosaic squares.
  • PointF BlindCoeff - Set (1,0) or (0,1) to "blind" effect.
  • float TransparencyCoeff - Set 1 if you want to make transparency of animation.
  • float TimeCoeff - Time coefficient
  • Padding Padding - Expands bounds of DoubleBitmap (it is useful for "wide" animations, like Rotate)
  • bool AnimateOnlyDifferences - Allows to animate only differences between start view of control and finish view (only for AnimationMode.Update). By default True.
To create custom animation, you need to handle events TransfromNeeded and/or NonLinearTransfromNeeded. The example see in demo application.

Animator has a good set of techniques to control the animation. Each method is asynchronous and synchronous versions. Asynchronous methods starts animation and returns immediately. Synchronous methods starts animation and wait while animation will be completed.

In addition the Animator supports queue of animated controls. You can use methods AddToQueue() and ClearQueue() for it.

Also, the Animator has methods to wait for all outstanding animations and methods to wait for the particular animation.

Moreover, the Animator has events AnimationCompleted and AllAnimationsCompleted that are invoked after any/all animation was completed.

Extended controls

The library contains extended TabControl. It is usual TabControl, but its tabs are animated:

Image 6

The TabControlEx conatins property Animation, where you can adjust animation of tabs.

Demo app

You can use the demo app for that would evaluate the possibilities of Animator:

Image 7

Decoration sample (BottomMirror mode):

Image 8


The Animator does not work with OLE-based controls (WebBrowser, RichTextBox). These controls do not paint itself when window is not visible. So we can not to grab bitmap from it.


19 Feb 2013 - First release.
20 Feb 2013 - TabControlEx was added, ClipRectangle is available for Update mode.
22 Feb 2013 - Performance was increased. Some bugs was fixed. Decoration sample was added.


This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Written By
Software Developer Freelancer
Ukraine Ukraine
I am Pavеl Tоrgаshоv, and I live in Kyiv, Ukraine.
I've been developing software since 1998.
Main activities: processing of large volumes of data, statistics, computer vision and graphics.

Comments and Discussions

QuestionWill this Library animation apply to Panels Pin
acaciasd5-Jul-21 0:19
acaciasd5-Jul-21 0:19 
QuestionDescription of Properties Pin
dherrmann28-Apr-20 10:46
dherrmann28-Apr-20 10:46 
QuestionCan this control be used to "shrink a winform" to the System Tray? Pin
Dan Desjardins15-May-19 5:48
Dan Desjardins15-May-19 5:48 
Can I apply this to the form itself rather than a control on a form? I am looking for a way to make my form shrink smoothly to the system tray. I am taking a snapshot of the form and placing the snapshot onto a new borderless form - then shrinking that. It works, but is far from smooth.
QuestionCombination Animation tow effect Pin
O.abdelaaziz1-Jan-18 2:47
O.abdelaaziz1-Jan-18 2:47 
AnswerRe: Combination Animation tow effect Pin
Guy DETIENNE6-May-18 21:58
Guy DETIENNE6-May-18 21:58 
BugMemroyLeak Pin
MOHAMED Salemyan12-Dec-17 1:34
MOHAMED Salemyan12-Dec-17 1:34 
GeneralRe: MemroyLeak Pin
Member 1150668410-May-18 13:45
Member 1150668410-May-18 13:45 
QuestionGreat work - how to slow animation? Pin
JimSharples12-Jul-16 23:01
JimSharples12-Jul-16 23:01 
PraiseCrazy function Pin
www.pixelup.sk31-May-16 11:43
www.pixelup.sk31-May-16 11:43 
QuestionFantastic- 5 Stars Pin
highcopic9-Mar-16 12:07
highcopic9-Mar-16 12:07 
QuestionNot working in c++/cli Pin
Prakash120613-Dec-15 17:53
Prakash120613-Dec-15 17:53 
QuestionMy vote of 10 :-) Pin
Christian Vogt13-Nov-15 23:49
professionalChristian Vogt13-Nov-15 23:49 
Questioncoool man !!! Pin
Yudhi Prabowo18-Aug-15 21:10
Yudhi Prabowo18-Aug-15 21:10 
QuestionGood Job Pin
Bhavesh Patel22-Jul-15 21:43
Bhavesh Patel22-Jul-15 21:43 
GeneralGreat Work Pin
bilal _hassan15-Jun-15 4:24
bilal _hassan15-Jun-15 4:24 
QuestionAnimationCompleted event Pin
chi2king21-Apr-15 1:10
chi2king21-Apr-15 1:10 
AnswerRe: AnimationCompleted event Pin
chi2king21-Apr-15 1:38
chi2king21-Apr-15 1:38 
GeneralRe: AnimationCompleted event Pin
chi2king21-Apr-15 1:42
chi2king21-Apr-15 1:42 
QuestionGreat! Pin
Member 1048720919-Mar-15 16:01
Member 1048720919-Mar-15 16:01 
QuestionVery Cool Pin
Brian Kinnish22-Feb-15 16:33
Brian Kinnish22-Feb-15 16:33 
GeneralMy vote of 5 Pin
majid torfi30-Oct-14 6:12
professionalmajid torfi30-Oct-14 6:12 
Questionanimation show and hide in one method Pin
Member 997106728-Oct-14 1:37
Member 997106728-Oct-14 1:37 
QuestionUseful Project Pin
yasir haris27-Oct-14 20:15
yasir haris27-Oct-14 20:15 
GeneralMessy code Pin
Mauro Sampietro17-Sep-14 0:20
Mauro Sampietro17-Sep-14 0:20 
GeneralRe: Messy code Pin
Pavel Torgashov17-Sep-14 0:29
professionalPavel Torgashov17-Sep-14 0:29 

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.