[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;
//透明度从高到低
---------------------------
调用:
private void Login_FormClosing(object sender, FormClosingEventArgs e)
{
AnimateWindow(this.Handle, 3000, AW_BLEND | AW_HIDE);
}
bool b = false;
private void Form5_Load(object sender, EventArgs e)
{
this.Opacity = 0;
this.timer1.Enabled = true;
}
private void Form5_FormClosing(object sender, FormClosingEventArgs e)
{
if (!this.timer1.Enabled)
{
this.timer1.Enabled = true;
b = true;
e.Cancel = true;//取消关闭,如果关闭了,看不到渐隐的效果
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!b)
{
if (this.Opacity < 1.0)
{
this.Opacity += 0.1;
if (this.Opacity == 1.0)
{
this.timer1.Enabled = false;
}
}
}
else
{
if (this.Opacity > 0)
{
this.Opacity -= 0.1;
if (this.Opacity == 0)
{
this.timer1.Enabled = false;
this.Close();
this.Dispose();//关闭窗体
}
}
}
}
设置winform 的Opacity值就行了。
再用个timer控件。就可以实现渐隐渐出的效果。
用计时器,控制 透明度 ,试试看
这个简单 ,直接联系我 我把源码你!!