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); } } } |
http://www.csharpwin.com/csharpspace/13109r8057.shtml
使用C#实现WinForm窗体的动画效果
http://www.cnblogs.com/xvqm00/archive/2009/02/16/1391313.html