Winform窗口渐进打开关闭效果实现 在Load中调用ShowFXCenter函数,在FormClosing中调用HideFXCenter函数: private void Form_Load(object sender, EventArgs e) { FormShowHideFx.ShowFXCenter(this.Handle, 300); } private void Form_FormClosing(object sender, FormClosingEventArgs e) { FormShowHideFx.HideFXCenter(this.Handle, 300); } 1 using System; 2 using System.Collections.Generic; 3 using System.Text; 4 using System.Runtime.InteropServices; 5 6 namespace Helper 7 { 8 /// <summary> 9 /// 窗口渐时显示隐藏 10 /// </summary> 11 public class FormShowHideFx 12 { 13 #region 变量 14 #region dwflag的取值 15 private const Int32 AW_HOR_POSITIVE = 0x00000001; 16 //从左到右显示 17 private const Int32 AW_HOR_NEGATIVE = 0x00000002; 18 //从右到左显示 19 private const Int32 AW_VER_POSITIVE = 0x00000004; 20 //从上到下显示 21 private const Int32 AW_VER_NEGATIVE = 0x00000008; 22 //从下到上显示 23 private const Int32 AW_CENTER = 0x00000010; 24 //若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;否则使窗口向外扩展,即展开窗口 25 private const Int32 AW_HIDE = 0x00010000; 26 //隐藏窗口,缺省则显示窗口 27 private const Int32 AW_ACTIVATE = 0x00020000; 28 //激活窗口。在使用了AW_HIDE标志后不能使用这个标志 29 private const Int32 AW_SLIDE = 0x00040000; 30 //使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略 31 private const Int32 AW_BLEND = 0x00080000; 32 #endregion 33 #endregion 34 35 #region 私有方法 36 [DllImport("user32")] 37 private static extern bool AnimateWindow(IntPtr whnd, int dwtime, int dwflag); 38 #endregion 39 40 #region 公开方法 41 /// <summary> 42 /// 由中心向边界扩展渐进打开窗口 43 /// </summary> 44 public static void ShowFXCenter(IntPtr wnd, int dwtime) 45 { 46 AnimateWindow(wnd, dwtime, AW_CENTER | AW_ACTIVATE | AW_SLIDE); 47 } 48 49 /// <summary> 50 /// 由边界向中心扩展渐进关闭窗口 51 /// </summary> 52 public static void HideFXCenter(IntPtr wnd, int dwtime) 53 { 54 AnimateWindow(wnd, dwtime, AW_CENTER | AW_HIDE | AW_SLIDE); 55 } 56 #endregion 57 } 58 } 59