出處:http://blog.csdn.net/qshpeng/article/details/1672359動畫
====================================================================ui
再看另一個設置窗口打開的特效已經居中的方法,你們能夠參考使用。this
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); }
出處:http://blog.csdn.net/lwmjm/article/details/8085752spa