一、适合自带窗体
[DllImport("user32.dll")]
//设置控件出现动画
private static extern bool AnimateWindow(IntPtr whnd, int dwtime, int dwflag);
//dwflag的取值如下
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;
int Location_x; int Location_y; int Location_y_start; private void Form1_Load(object sender, EventArgs e) { Location_x = SystemInformation.WorkingArea.Width - this.Width; Location_y = SystemInformation.WorkingArea.Height - this.Height * index; Location_y_start = SystemInformation.WorkingArea.Height; this.Location = new Point(Location_x, SystemInformation.WorkingArea.Height); for (int i = 0; i <this.Height; i += 10) { this.Location = new Point(Location_x, Location_y_start - i); Thread.Sleep(30); //等30微秒再动 } }
淡出:
private void FrmMessageInfo_FormClosing(object sender, FormClosingEventArgs e) { for (int i = 0; i < TranckLength; i += 10) { this.Location = new Point(Location_x, Location_y + i); Thread.Sleep(30); //等30微秒再动 } }