下面是实例的cs代码
public partial class frm_Main : Form
{
//使用Windows Api AnimateWindow
[DllImport("user32.dll", EntryPoint = "AnimateWindow")]
private static extern bool AnimateWindow(IntPtr handle, int ms, int flags);
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标志,则使窗口向内重叠,即收缩窗口;否则使窗口向外扩展,即展开窗口
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;//透明度从高到低
public frm_Main()
{
InitializeComponent();
//设置窗体的样式为无边框
this.FormBorderStyle = FormBorderStyle.None;
//获取屏幕工作区域
Rectangle rectWork=Screen.GetWorkingArea(this);
//设置窗体的位置为右下角
this.Location = new Point(rectWork.Width - this.Width,rectWork.Height - this.Height);
//窗体的位置由Location属性确定
//this.StartPosition = FormStartPosition.Manual;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
AnimateWindow(this.Handle, 2000, AW_VER_POSITIVE);// 自上而下。
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void frm_Main_Load(object sender, EventArgs e)
{
//调用方法实现显示效果
AnimateWindow(this.Handle, 2000, AW_VER_NEGATIVE + AW_VER_POSITIVE); // 自下向上。
}
}
效果,实现一个桌面右下角往上升的一个窗体
个人感觉用一个定时器来控制窗体的location或许效果更爽!