您的位置:首页 > 其它

类似qq弹窗,自动消失

2015-07-20 22:57 288 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FormCPM
{
public partial class Form1 : Form
{
const int countDown = 60;//倒计时
int currCountDown = countDown;//倒计时
bool isCount = true;
Thread thread;
public Form1()
{
InitializeComponent();
thread = new Thread(() =>
{
while (true)
{
if (isCount)
{
if (currCountDown <= 0)
{
this.Invoke(new Action(() =>
{
this.Close();
}));
break;
}
else
{
Thread.Sleep(100);
currCountDown--;
this.Invoke(new Action(() =>
{
this.Opacity = this.Opacity - this.Opacity / countDown;
}));

}
}
else
{
Thread.Sleep(10);
}
}
});
thread.IsBackground = true;
}
[DllImport("user32")]

private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);

//下面是可用的常量,按照不合的动画结果声明本身须要的

private const int AW_HOR_POSITIVE = 0x0001;//自左向右显示窗口,该标记可以在迁移转变动画和滑动动画中应用。应用AW_CENTER标记时忽视该标记

private const int AW_HOR_NEGATIVE = 0x0002;//自右向左显示窗口,该标记可以在迁移转变动画和滑动动画中应用。应用AW_CENTER标记时忽视该标记

private const int AW_VER_POSITIVE = 0x0004;//自顶向下显示窗口,该标记可以在迁移转变动画和滑动动画中应用。应用AW_CENTER标记时忽视该标记

private const int AW_VER_NEGATIVE = 0x0008;//自下向上显示窗口,该标记可以在迁移转变动画和滑动动画中应用。应用AW_CENTER标记时忽视该标记该标记

private const int AW_CENTER = 0x0010;//若应用了AW_HIDE标记,则使窗口向内重叠;不然向外扩大

private const int AW_HIDE = 0x10000;//隐蔽窗口

private const int AW_ACTIVE = 0x20000;//激活窗口,在应用了AW_HIDE标记后不要应用这个标记

private const int AW_SLIDE = 0x40000;//应用滑动类型动画结果,默认为迁移转变动画类型,当应用AW_CENTER标记时,这个标记就被忽视

private const int AW_BLEND = 0x80000;//应用淡入淡出结果

private void Form1_Load(object sender, EventArgs e)
{

int x = Screen.PrimaryScreen.WorkingArea.Right - this.Width;

int y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height;

this.Location = new Point(x, y);//设置窗体在屏幕右下角显示

AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_ACTIVE | AW_VER_NEGATIVE);
thread.Start();

}private void Form1_MouseEnter(object sender, EventArgs e)
{
isCount = false;
currCountDown = countDown;
this.Opacity = 1d;
}

private void Form1_MouseLeave(object sender, EventArgs e)
{
isCount = true;
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: