WinFormフォームのポップアップとクローズ時のアニメーション

3410 ワード

WinFormアプリケーションを追加するために、Formのログインとオフ時の動感効果をWindows APIでアニメーション効果を実現します.具体的な方法は以下の通りです.
        #region            ,  Windows API  
        /// 
        ///     :                     。          :         。
        ///     :BOOL AnimateWindow(HWND hWnd,DWORD dwTime,DWORD dwFlags)
        /// hWnd:            。
        /// dwTime:         (    ),            200  。
        /// dwFags:      。                   。
        /// 
        ///             。
        ///          (    ),            200  。
        ///       。                   。
        ///       ,      ;      ,     。
        /// 
        ///           :         ;            ;            。          ,   GetLastError  。
        ///  :   AW_HOR_POSITIVE AW_HOR_NEGTVE AW_VER_POSITVE AW_VER_NEGATIVE         。
        ///                           WM_PRINT WM_PRINTCLIENT  。   ,  ,        WM_PRINTCLIENT  ,          WM_PRINT  。
        ///  :WIDDOWS NT:5.0    :Windows:98    ;Windows CE:   ;   :Winuser.h;   :user32.lib。
        /// 
        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);

        /// 
        ///       。          。   AW_CENTER   ,        。
        /// 
        public const int AW_SLIDE = 0x40000;

        /// 
        ///     。    AW_HIDE           。
        /// 
        public const int AW_ACTIVATE = 0x20000;

        /// 
        ///       。   hWnd                。
        /// 
        public const int AW_BLEND = 0x80000;

        /// 
        ///     ,       。(     )
        /// 
        public const int AW_HIDE = 0x10000;

        /// 
        ///     AW_HIDE  ,        ;    AW_HIDE  ,        。
        /// 
        public const int AW_CENTER = 0x0010;

        /// 
        ///         。                  。   AW_CENTER   ,       。
        /// 
        public const int AW_HOR_POSITIVE = 0x0001;

        /// 
        ///         。                  。   AW_CENTER   ,       。
        /// 
        public const int AW_VER_POSITIVE = 0x0004;

        /// 
        ///         。                  。   AW_CENTER   ,       。
        /// 
        public const int AW_HOR_NEGATIVE = 0x0002;

        /// 
        ///         。                  。   AW_CENTER   ,       。
        /// 
        public const int AW_VER_NEGATIVE = 0x0008;

        #endregion
FormのLoadおよびCloseイベントで、次のように呼び出されます.
        /// 
        ///        ,    
        /// 
        /// 
        /// 
        private void MainForm_Load(object sender, EventArgs e)
        {
            FormUtils.AnimateWindow(this.Handle, 200, FormUtils.AW_CENTER);
        }
        /// 
        ///        ,    
        /// 
        /// 
        /// 
        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            FormUtils.AnimateWindow(this.Handle, 200, FormUtils.AW_CENTER | FormUtils.AW_HIDE);
        }