https://www.cnblogs.com/mq0036/p/6421946.html
using System.Runtime.InteropServices; public class Win32 { public const Int32 AW_HOR_POSITIVE = 0x00000001; // 從左到右打開窗口 public const Int32 AW_HOR_NEGATIVE = 0x00000002; // 從右到左打開窗口 public const Int32 AW_VER_POSITIVE = 0x00000004; // 從上到下打開窗口 public const Int32 AW_VER_NEGATIVE = 0x00000008; // 從下到上打開窗口 public const Int32 AW_CENTER = 0x00000010; //若使用了AW_HIDE標志,則使窗口向內重疊;若未使用AW_HIDE標志,則使窗口向外擴展。 public const Int32 AW_HIDE = 0x00010000; //隱藏窗口,缺省則顯示窗口。 public const Int32 AW_ACTIVATE = 0x00020000; //激活窗口。在使用了AW_HIDE標志后不要使用這個標志。 public const Int32 AW_SLIDE = 0x00040000; //使用滑動類型。缺省則為滾動動畫類型。當使用AW_CENTER標志時,這個標志就被忽略。 public const Int32 AW_BLEND = 0x00080000; //使用淡出效果。只有當hWnd為頂層窗口的時候才可以使用此標志。 [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern bool AnimateWindow( IntPtr hwnd, // handle to window int dwTime, // duration of animation int dwFlags // animation type ); } /**//*淡入窗體*/ private void Form_Load(object sender, EventArgs e) { Win32.AnimateWindow(this.Handle, 2000, Win32.AW_BLEND); } /**//*淡出窗體*/ private void Form_FormClosing(object sender, FormClosingEventArgs e) { Win32.AnimateWindow(this.Handle, 2000, Win32.AW_SLIDE | Win32.AW_HIDE | Win32.AW_BLEND); } 2,窗體居中 Code /**//// <summary> /// 頁面居中 /// </summary> public static void SetMid(Form form) { // Center the Form on the user's screen everytime it requires a Layout. form.SetBounds((Screen.GetBounds(form).Width / 2) - (form.Width / 2), (Screen.GetBounds(form).Height / 2) - (form.Height / 2), form.Width, form.Height, BoundsSpecified.Location); }