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);
}
效果圖:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
窗體進入和退出的動畫效果
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport(
"user32"
)]
private
static
extern
bool
AnimateWindow(IntPtr hwnd,
int
dwTime,
int
dwFlags);
//標志描述:
const
int
AW_SLIDE = 0x40000;
//使用滑動類型。缺省則為滾動動畫類型。當使用AW_CENTER標志時,這個標志就被忽略。
const
int
AW_ACTIVATE = 0x20000;
//激活窗口。在使用了AW_HIDE標志后不要使用這個標志。
const
int
AW_BLEND = 0x80000;
//使用淡出效果。只有當hWnd為頂層窗口的時候才可以使用此標志。
const
int
AW_HIDE = 0x10000;
//隱藏窗口,缺省則顯示窗口。(關閉窗口用)
const
int
AW_CENTER = 0x0010;
//若使用了AW_HIDE標志,則使窗口向內重疊;若未使用AW_HIDE標志,則使窗口向外擴展。
const
int
AW_HOR_POSITIVE = 0x0001;
//自左向右顯示窗口。該標志可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標志時,該標志將被忽略。
const
int
AW_VER_POSITIVE = 0x0004;
//自頂向下顯示窗口。該標志可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標志時,該標志將被忽略。
const
int
AW_HOR_NEGATIVE = 0x0002;
//自右向左顯示窗口。該標志可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標志時,該標志將被忽略。
const
int
AW_VER_NEGATIVE = 0x0008;
//自下向上顯示窗口。該標志可以在滾動動畫和滑動動畫中使用。當使用AW_CENTER標志時,該標志將被忽略。
private
void
Form1_Load(
object
sender, EventArgs e)
{
AnimateWindow(
this
.Handle, 1000, AW_CENTER );
}
private
void
Form1_FormClosing(
object
sender, FormClosingEventArgs e)
{
AnimateWindow(
this
.Handle, 1000, AW_HIDE | AW_CENTER);
}
}
}
|
WinForm實現win7 Aero磨砂效果介紹
http://www.csharpwin.com/csharpspace/13109r8057.shtml
使用C#實現WinForm窗體的動畫效果
http://www.cnblogs.com/xvqm00/archive/2009/02/16/1391313.html