動畫顯示窗體
阿新 • • 發佈:2018-12-14
實現效果:
知識運用:
API函式AnimateWindows
[DllImportAttribute("user32.dll")]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime,int dwFlags);
- hwnd: IntPtr,視窗控制代碼
- dwTime:動畫的持續時間
- dwFlags:動畫型別選項 常量值如下
實現程式碼:
private const int AW_SLIDE = 0x00040000; private const int AW_VER_NEGATIVE = 0x00000008; private const int AW_HIDE = 0x00010000; public Form1() { InitializeComponent(); AnimateWindow(this.Handle, 3000, AW_SLIDE + AW_VER_NEGATIVE); //開始窗體動畫 } [DllImportAttribute("user32.dll")] private static extern bool AnimateWindow(IntPtr hwnd,int dwTime,int dwFlags); //重寫API函式用來執行窗體動畫顯示操作 //繪製漸變背景 private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Color sColor = Color.Green; //顏色1,2 Color eColor = Color.Black; //例項化刷子 (上色域 開始色 結束色 顏色方向) Brush b = new LinearGradientBrush(this.ClientRectangle,sColor,eColor,LinearGradientMode.Vertical); g.FillRectangle(b,this.ClientRectangle); //進行上色 } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { AnimateWindow(this.Handle, 3000, AW_SLIDE + AW_VER_NEGATIVE+AW_HIDE); //結束窗體動畫 }