Sunday, July 15, 2012

Animate Form - Slowly Show and Close

This is something makes a simple Form more aesthetically rich. Form cosmetic aspects plays major part but launch of a form also plays a major aspects how user perceive it. I was looking ways to do that, one way is to use timer to change the opacity of form during show and hide. Other way and better way to animate it. User need to use user32.dll for it.


Add following reference
using System.Runtime.InteropServices;

Initialization - add following in FormClass

namespace TestNamespace
    public partial class TestForm : Form
        static extern bool AnimateWindow(IntPtr hWnd, int time, AnimateWindowFlags flags);
        enum AnimateWindowFlags
            AW_HOR_POSITIVE = 0x00000001,
            AW_HOR_NEGATIVE = 0x00000002,
            AW_VER_POSITIVE = 0x00000004,
            AW_VER_NEGATIVE = 0x00000008,
            AW_CENTER = 0x00000010,
            AW_HIDE = 0x00010000,
            AW_ACTIVATE = 0x00020000,
            AW_SLIDE = 0x00040000,
            AW_BLEND = 0x00080000

Need to handle two form events "XXX_Load" and "XXX_FormClosing" and add following code in that

private void TestForm_Load(object sender, EventArgs e)
   AnimateWindow(this.Handle, 1000, AnimateWindowFlags.AW_BLEND | AnimateWindowFlags.AW_ACTIVATE);

private void TestForm_FormClosing(object sender, FormClosingEventArgs e)
   AnimateWindow(this.Handle, 1000, AnimateWindowFlags.AW_BLEND | AnimateWindowFlags.AW_HIDE);

Reference :-


  1. Dear, I like your blog very much, I can get many useful information. Hope that we can communicate with each other. By the way, have you ever used memory card software ? Unfortunately I lost my memory card data. I do not know how to do.

  2. If you are in Jaipur and need beautiful Jaipur Escorts or white skin Jaipur Escorts then you can simply book call girls in Jaipur from one of the best escort agency named Jaipur Escorts. It is No.1 premier escort agency and provide both incall or outcall facility to clients.Please click on the following link to check the official websites Jaipur Escorts