WinForm 窗体动画效果
窗体动画效果,使用windows提供的API:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
[DllImportAttribute("user32.dll")]
// IntPtr hwnd: 目标窗口的句柄对象, 一般为 this.Handle
// int dwTime: 动画的持续时间, 数值越大动画效果的时间越长
// int dwFlags: 动画效果类型选项
private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
/// <summary>
/// AW_HOR_POSITIVE : 自左向右显示窗口
/// </summary>
public const Int32 AW_HOR_POSITIVE = 0x00000001;
/// <summary>
/// AW_HOR_NEGATIVE: 自右向左显示窗口
/// </summary>
public const Int32 AW_HOR_NEGATIVE = 0x00000002;
/// <summary>
/// AW_VER_POSITVE: 自顶向下显示窗口
/// </summary>
public const Int32 AW_VER_POSITIVE = 0x00000004;
/// <summary>
/// AW_VER_NEGATIVE : 自下向上显示窗口
/// </summary>
public const Int32 AW_VER_NEGATIVE = 0x00000008;
/// <summary>
/// AW_CENTER: 与 AW_HIDE 效果配合使用则效果为窗口几内重叠, 单独使用窗口向外扩展.
/// </summary>
public const Int32 AW_CENTER = 0x00000010;
/// <summary>
/// AW_HIDE: 隐藏窗口
/// </summary>
public const Int32 AW_HIDE = 0x00010000;
/// <summary>
/// AW_ACTIVE: 激活窗口, 在使用了 AW_HIDE 效果时不可使用此效果
/// </summary>
public const Int32 AW_ACTIVATE = 0x00020000;
/// <summary>
/// AW_SLIDE : 使用滑动类型, 默认为该类型. 当使用 AW_CENTER 效果时, 此效果被忽略
/// </summary>
public const Int32 AW_SLIDE = 0x00040000;
/// <summary>
/// AW_BLEND: 使用淡入效果
/// </summary>
public const Int32 AW_BLEND = 0x00080000;
public Form1()
{
InitializeComponent();
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_CENTER);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
[DllImportAttribute("user32.dll")]
// IntPtr hwnd: 目标窗口的句柄对象, 一般为 this.Handle
// int dwTime: 动画的持续时间, 数值越大动画效果的时间越长
// int dwFlags: 动画效果类型选项
private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
/// <summary>
/// AW_HOR_POSITIVE : 自左向右显示窗口
/// </summary>
public const Int32 AW_HOR_POSITIVE = 0x00000001;
/// <summary>
/// AW_HOR_NEGATIVE: 自右向左显示窗口
/// </summary>
public const Int32 AW_HOR_NEGATIVE = 0x00000002;
/// <summary>
/// AW_VER_POSITVE: 自顶向下显示窗口
/// </summary>
public const Int32 AW_VER_POSITIVE = 0x00000004;
/// <summary>
/// AW_VER_NEGATIVE : 自下向上显示窗口
/// </summary>
public const Int32 AW_VER_NEGATIVE = 0x00000008;
/// <summary>
/// AW_CENTER: 与 AW_HIDE 效果配合使用则效果为窗口几内重叠, 单独使用窗口向外扩展.
/// </summary>
public const Int32 AW_CENTER = 0x00000010;
/// <summary>
/// AW_HIDE: 隐藏窗口
/// </summary>
public const Int32 AW_HIDE = 0x00010000;
/// <summary>
/// AW_ACTIVE: 激活窗口, 在使用了 AW_HIDE 效果时不可使用此效果
/// </summary>
public const Int32 AW_ACTIVATE = 0x00020000;
/// <summary>
/// AW_SLIDE : 使用滑动类型, 默认为该类型. 当使用 AW_CENTER 效果时, 此效果被忽略
/// </summary>
public const Int32 AW_SLIDE = 0x00040000;
/// <summary>
/// AW_BLEND: 使用淡入效果
/// </summary>
public const Int32 AW_BLEND = 0x00080000;
public Form1()
{
InitializeComponent();
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_CENTER);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);
}
}
}