using System.Runtime.InteropServices;[DllImport("user32")]private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);//下面是可用的常量,按照不合的動畫結果聲明本身須要的private const int AW_HOR_POSITIVE = 0 x0001;//自左向右顯示視窗,該標記可以在遷移轉變動畫和滑動動畫中應用。應用AW_CENTER標記時忽視該標記private const int AW_HOR_NEGATIVE = 0 x0002;//自右向左顯示視窗,該標記可以在遷移轉變動畫和滑動動畫中應用。應用AW_CENTER標記時忽視該標記private const int AW_VER_POSITIVE = 0 x0004;//自頂向下顯示視窗,該標記可以在遷移轉變動畫和滑動動畫中應用。應用AW_CENTER標記時忽視該標記private const int AW_VER_NEGATIVE = 0 x0008;//自下向上顯示視窗,該標記可以在遷移轉變動畫和滑動動畫中應用。應用AW_CENTER標記時忽視該標記該標記private const int AW_CENTER = 0 x0010;//若應用了AW_HIDE標記,則使視窗向內重疊;不然向外擴大private const int AW_HIDE = 0 x10000;//隱蔽視窗private const int AW_ACTIVE = 0 x20000;//啟用視窗,在應用了AW_HIDE標記後不要應用這個標記private const int AW_SLIDE = 0 x40000;//應用滑動類型動畫結果,預設為遷移轉變動畫類型,當應用AW_CENTER標記時,這個標記就被忽視private const int AW_BLEND = 0 x80000;//應用淡入淡出結果private void Form1_Load(object sender, EventArgs e){ int x = Screen.PrimaryScreen.WorkingArea.Right - this.Width; int y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height; this.Location = new Point(x, y);//設定表單在螢幕右下角顯示 AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_ACTIVE | AW_VER_NEGATIVE);}private void Form1_FormClosing(object sender, FormClosingEventArgs e){ AnimateWindow(this.Handle, 1000, AW_BLEND | AW_HIDE);}///以下還有第二種方法////// 表單動畫函數 注意:要引用System.Runtime.InteropServices;////// 指定產生動畫的視窗的控制代碼 /// 指定動畫持續的時間 /// 指定動畫類型,可以是一個或多個標誌的組合。 ///[DllImport("user32")]private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);//下面是可用的常量,根據不同的動畫效果聲明自己需要的private const int AW_HOR_POSITIVE = 0x0001;//自左向右顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌private const int AW_HOR_NEGATIVE = 0x0002;//自右向左顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌private const int AW_VER_POSITIVE = 0x0004;//自頂向下顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌private const int AW_VER_NEGATIVE = 0x0008;//自下向上顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌該標誌private const int AW_CENTER = 0x0010;//若使用了AW_HIDE標誌,則使視窗向內重疊;否則向外擴充private const int AW_HIDE = 0x10000;//隱藏視窗private const int AW_ACTIVE = 0x20000;//啟用視窗,在使用了AW_HIDE標誌後不要使用這個標誌private const int AW_SLIDE = 0x40000;//使用滑動類型動畫效果,預設為滾動動畫類型,當使用AW_CENTER標誌時,這個標誌就被忽略private const int AW_BLEND = 0x80000;//使用淡入淡出效果private void FrmMsg_Load(object sender, EventArgs e){ int x = Screen.PrimaryScreen.WorkingArea.Right - this.Width; int y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height; this.Location = new Point(x, y);//設定表單在螢幕右下角顯示 AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_ACTIVE | AW_VER_NEGATIVE);}private void FrmMsg_FormClosing(object sender, FormClosingEventArgs e){ AnimateWindow(this.Handle, 1000, AW_BLEND | AW_HIDE);}