Monday, November 24, 2008

Animating a Windows Form

Requirment

To animate a windows form while displaying it to user , just like a powerpoint slides effects.

Solution

To get such powerpoint slides effect can be achieved using Win32 API . the only problem here is that its unmanged code.

Note : sample code below is in C#

1) Add a reference to you class file
using System.Runtime.InteropServices;

2) import user32 dll with following syntax
[DllImport("User32.dll")]
static extern bool AnimateWindow(System.IntPtr handle, int time, int value);

3) call AnimateWindow function at windows form load event


Arguments
1) Handler(this. handle) of form(to be animated)
2) time(in milliseconds) to specify how much time animation will take (faster or slower)
3) values(in hexadecimal ) which specify how the form will be displayed (left to right, right to left, top to bottom, bottom to top or center etc..)


The last values are or'd together and can be any of the following:

&O1 = Animate the window from left to right. This flag can be used with roll or slid eanimation It is ignored when used with the &H10 flag.

&H2 = Animate the window from right to left. This flag can be used with roll or slide animation. It is ignored when used with the &H10 flag.

&H4 = Animate the window from top to bottom. This flag can be used with roll or slide animation. It is ignored when used with the &H10flag.

&H8 = Animate the window from bottom to top. This flag can be used with roll or slide animation. It is ignored when used with the &H10flag.

&H10 = Makes the window appear to collapse inward if the &H10000 flagis used or expand outward if the &H10000 flag is not used.

&H10000 = Hides the window. By default, the window is shown.&H20000 = Activates the window. Do not use this flag with &H10000.

&H40000 = Uses slide animation. By default, roll animation is used. This flag is ignored when used with the &H10 flag.

&H80000 = Uses a fade effect. This flag can be used only if hwnd is a top-level window.

No comments: