C#设计闪烁窗体
C#设计闪烁窗体
介绍:
常用QQ的用户都会知道,如果当前信息窗体并不是活动窗体,但有消息时,窗体就会闪烁,引起用户注意,本文章讲述实现此功能。运行程序点击开始。
过程:
1.创建一个VS的windows应用程序项目,项目默认窗体为Form1.
2.在窗口添加两个Button和Timer组件。
3.在开始闪烁时按钮代码如下:
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
}
4.停止闪烁按钮点击事件代码如下;
private void button2_Click(object sender, EventArgs e)
{
this.timer1.Enabled = false;
}
5.在 timer组建的Tick事件中变下如下代码:
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
} private void timer1_Tick(object sender, EventArgs e)
{
FlashWindow(this.Handle, true);
}
运算结果:
关键技术解析:
.net 平台没有能直接实现窗体闪烁的类和方法,需要调用API函数已实现FlashWindow()。
所以在C#中声明如下:
[dllimport ("user32")]
private static extern long FashWindow(initPtr handle,bool bInvert);
并且必须引入命名空间
System.Runtime.interopServices.
扩展:
可实现图片闪烁,按钮闪烁等。
