【转】以动画形式显示窗体,以及关闭窗体的效果

/******************************************************************
 * 
 *  ^_^ 恶猫 独门商标 挖哈哈
 * 
 *  QQ:>23559055 
 * 
 *  Site:>http://emao.me  
 * 
 * ================================================================
 * 
 * 说明:
 * 
 *        1.命名空间: Emao_AniWindow
 *          类名    : AniWindow
 * 
 *         2.使用: AniWindowClass.AniWindow(this.Handle,100,1,this);
 * 
 *        3.参数说明:AniWindow(窗口句柄,动画样式,打开或关闭标志,实例表单);
 *          窗口句柄: this.Handle 
 *          动画样式: 0  -> 普通显示
 *                    1  -> 从左向右显示
 *                     2  -> 从右向左显示
 *                     3  -> 从上到下显示
 *                     4  -> 从下到上显示
 *                     5  -> 透明渐变显示
 *                     6  -> 从中间向四周
 *                     7  -> 左上角伸展
 *                     8  -> 左下角伸展
 *                     9  -> 右上角伸展
 *                     10 -> 右下角伸展
 *          开关标志: 0为关闭窗口 1为打开窗口
 *          实例表单: 为了去除Label的BUG, 取值 this 
 * 
 * ===============================================================
 * 
 * 另有不得不说的BUG,目前我只知当FORM上有可视的Label的时候,会出错,现已解决.
 * 但不知道还有没有别的控件会引发错误,
 * 
 * 还有,如果是Form上的Label,程序会自动设为不可视,如果是Panel里面的....X_X 还是会出错.
 * 所以,如果你的程序里有LABEL,还是在PANEL中,,,那你只好自己写代码来实现可视不可视喽...
 * 
 ******************************************************************/
using System;
using System.Windows.Forms;
namespace Emao_AniWindow
{
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    public static class AniWindowClass
    {
        [System.Runtime.InteropServices.DllImport("user32")]
        private static extern bool AnimateWindow(IntPtr hwnd,int dwTime, int dwFlags);
        private const int AW_HOR_POSITIVE = 0x0001;
        private const int AW_HOR_NEGATIVE = 0x0002;
        private const int AW_VER_POSITIVE = 0x0004;
        private const int AW_VER_NEGATIVE = 0x0008;
        private const int AW_CENTER = 0x0010;
        private const int AW_HIDE = 0x10000;
        private const int AW_ACTIVATE = 0x20000;
        private const int AW_SLIDE = 0x40000;
        private const int AW_BLEND = 0x80000;
        private static int CloseOpen = 0x20000;

        public static void AniWindow(IntPtr hwnd,int dwFlags,int CloseOrOpen,System.Windows.Forms.Form myform)
        {
            try
            {
                if(CloseOrOpen==1)
                {
                    foreach(System.Windows.Forms.Control mycontrol in myform.Controls)
                    {
                        string m=mycontrol.GetType().ToString();
                        m=m.Substring(m.Length-5);
                        if(m=="Label")
                        {
                            mycontrol.Visible=false;
                        }
                    }
                }
                //打开or关闭 0是关闭  1是打开
                if(CloseOrOpen==0){CloseOpen=0x10000;}
                if(dwFlags==100)
                {
                    int zz=10;
                    Random a=new Random();
                    dwFlags=(int)a.Next(zz);
                }

            
                switch(dwFlags)
                {
                    case 0://普通显示
                        AnimateWindow(hwnd,200,AW_ACTIVATE);
                        break;
                    case 1://从左向右显示
                        AnimateWindow(hwnd,200,AW_HOR_POSITIVE|CloseOpen);
                        break;
                    case 2://从右向左显示
                        AnimateWindow(hwnd,200,AW_HOR_NEGATIVE|CloseOpen);
                        break;
                    case 3://从上到下显示
                        AnimateWindow(hwnd,200,AW_VER_POSITIVE|CloseOpen);
                        break;
                    case 4://从下到上显示
                        AnimateWindow(hwnd,200,AW_VER_NEGATIVE|CloseOpen);
                        break;
                    case 5://透明渐变显示
                        AnimateWindow(hwnd,200,AW_BLEND|CloseOpen);
                        break;
                    case 6://从中间向四周
                        AnimateWindow(hwnd,200,AW_CENTER|CloseOpen);
                        break;
                    case 7://左上角伸展
                        AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_POSITIVE|AW_VER_POSITIVE|CloseOpen);
                        break;
                    case 8://左下角伸展
                        AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_POSITIVE|AW_VER_NEGATIVE|CloseOpen);
                        break;
                    case 9://右上角伸展
                        AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_NEGATIVE|AW_VER_POSITIVE|CloseOpen);
                        break;
                    case 10://右下角伸展
                        AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_NEGATIVE|AW_VER_NEGATIVE|CloseOpen);
                        break;
                }
                if(CloseOrOpen==1)
                {
                    foreach(System.Windows.Forms.Control mycontrol in myform.Controls)
                    {
                        string m=mycontrol.GetType().ToString();
                        m=m.Substring(m.Length-5);
                        if(m=="Label")
                        {
                            mycontrol.Visible=true;
                        }
                    }
                }
            }
            catch{}
        }
    }

}

以动画形式显示窗体,以及关闭窗体的效果。容易使用。 
Form_load : AniWindowClass.AniWindow(this.Handle, 100, 1, this); 
Form_closed: AniWindowClass.AniWindow(this.Handle, 100, 0, this); 

不错,楼主的使用方法有点误导人。 
 private void LoginFrm_Load(object sender, EventArgs e) { 
            AniWindowClass.AniWindow(this.Handle, 5, 1, this); 
        } 

原文:http://www.oschina.net/code/snippet_191468_13275

原文地址:https://www.cnblogs.com/anduinlothar/p/3523393.html