动画启动窗口的类

来源:互联网 发布:linux 获取cpu 编辑:程序博客网 时间:2024/06/05 17:37
* 说明:
*
* 1.命名空间: Apc_AniWindow
* 类名 : AniWindow
*
* 2.声明: AniWindow a=new AniWindow(this.Handle,100,1,this);
*
* 3.参数说明:AniWindow(窗口句柄,动画样式,打开或关闭标志,实例表单);
* 窗口句柄: this.Handle
* 动画样式: 0 -> 普通显示
* 1 -> 从左向右显示
* 2 -> 从右向左显示
* 3 -> 从上到下显示
* 4 -> 从下到上显示
* 5 -> 透明渐变显示
* 6 -> 从中间向四周
* 7 -> 左上角伸展
* 8 -> 左下角伸展
* 9 -> 右上角伸展
* 10 -> 右下角伸展
* 开关标志: 0为关闭窗口 1为打开窗口
* 实例表单: 为了去除Label的BUG, 取值 this
*
* ===============================================================
*
* 另有不得不说的BUG,目前我只知当FORM上有可视的Label的时候,会出错,现已解决.
* 但不知道还有没有别的控件会引发错误,
*
* 还有,如果是Form上的Label,程序会自动设为不可视,如果是Panel里面的....X_X 还是会出错.
* 所以,如果你的程序里有LABEL,还是在PANEL中,,,那你只好自己写代码来实现可视不可视喽...
*
******************************************************************/
using System;
using System.Windows.Forms;
namespace Apc_AniWindow
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class AniWindow
{
[System.Runtime.InteropServices.DllImport("user32")]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime, int dwFlags);
private const int AW_HOR_POSITIVE = 0x0001;
private const int AW_HOR_NEGATIVE = 0x0002;
private const int AW_VER_POSITIVE = 0x0004;
private const int AW_VER_NEGATIVE = 0x0008;
private const int AW_CENTER = 0x0010;
private const int AW_HIDE = 0x10000;
private const int AW_ACTIVATE = 0x20000;
private const int AW_SLIDE = 0x40000;
private const int AW_BLEND = 0x80000;
private int CloseOpen=0x20000;

public AniWindow(IntPtr hwnd,int dwFlags,int CloseOrOpen,System.Windows.Forms.Form myform)
{
try
{
if(CloseOrOpen==1)
{
foreach(System.Windows.Forms.Control mycontrol in myform.Controls)
{
string m=mycontrol.GetType().ToString();
m=m.Substring(m.Length-5);
if(m=="Label")
{
mycontrol.Visible=false; //这里是在动画效果之前,把表单上可视的LABEL设为不可视
}
}
}
//打开or关闭 0是关闭 1是打开
if(CloseOrOpen==0){CloseOpen=0x10000;}
if(dwFlags==100)
{
int zz=10;
Random a=new Random();
dwFlags=(int)a.Next(zz);
}


switch(dwFlags)
{
case 0://普通显示
AnimateWindow(hwnd,200,AW_ACTIVATE);
break;
case 1://从左向右显示
AnimateWindow(hwnd,200,AW_HOR_POSITIVE|CloseOpen);
break;
case 2://从右向左显示
AnimateWindow(hwnd,200,AW_HOR_NEGATIVE|CloseOpen);
break;
case 3://从上到下显示
AnimateWindow(hwnd,200,AW_VER_POSITIVE|CloseOpen);
break;
case 4://从下到上显示
AnimateWindow(hwnd,200,AW_VER_NEGATIVE|CloseOpen);
break;
case 5://透明渐变显示
AnimateWindow(hwnd,200,AW_BLEND|CloseOpen);
break;
case 6://从中间向四周
AnimateWindow(hwnd,200,AW_CENTER|CloseOpen);
break;
case 7://左上角伸展
AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_POSITIVE|AW_VER_POSITIVE|CloseOpen);
break;
case 8://左下角伸展
AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_POSITIVE|AW_VER_NEGATIVE|CloseOpen);
break;
case 9://右上角伸展
AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_NEGATIVE|AW_VER_POSITIVE|CloseOpen);
break;
case 10://右下角伸展
AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_NEGATIVE|AW_VER_NEGATIVE|CloseOpen);
break;
}
if(CloseOrOpen==1)
{
foreach(System.Windows.Forms.Control mycontrol in myform.Controls)
{
string m=mycontrol.GetType().ToString();
m=m.Substring(m.Length-5);
if(m=="Label")
{
mycontrol.Visible=true; //这里恢复LABEL的可视.
}
}
}
}
catch{}
}
}

}


把这代码,贴到.NET环境中, 直接编译就可以了.

或者直接放在代码中,用就可以了.

欢迎交流.

另外,我用 form的 region属性,也做了一个,普通的动画例子,但是没有API的效果好,(但是绝对没有BUG,比如label这样的错)

但可惜的是,一指定 form的 region , 当窗体改变大小时, 还要重新设置一下, region

哎.....不知道有什么好的办法..更好的办法..... 

 
原创粉丝点击