码迷,mamicode.com
首页 > Windows程序 > 详细

设计闪烁的窗体

时间:2016-07-12 19:22:34      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:

1、概述

    qq对话框接收到消息时,如果对话框不是活动窗体,对话框就会闪烁来提示用户有新消息需要阅读,本文就是要实现这种形式的闪烁窗体。

2、设计详情

    .NET没有直接提供实现窗体闪烁的类和方法,需要调用Windows的API函数FlashWindow()实现。该函数在c#中的声明如下:

     [DllImport("user32")]
     private static extern long FlashWindow(IntPtr handle,bool bInvert);

此函数可以实现窗体闪烁,但只能闪烁一次,如果要实现多次闪烁,可以借助定时器Timer组件实现。

注意:在Windows应用程序中使用Windows API 函数时,必须引入命名空间 System.Runtime.InteropServices;

3、窗体设计

    技术分享

4、程序代码

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using System.Runtime.InteropServices;
10 
11 namespace Kaifafanli
12 {
13     
14     public partial class Form6 : Form
15     {
16         [DllImport("user32")]
17         private static extern long FlashWindow(IntPtr handle,bool bInvert);
18         public Form6()
19         {
20             InitializeComponent();
21         }
22 
23         private void timer1_Tick(object sender, EventArgs e)
24         {
25             FlashWindow(this.Handle, true);
26         }
27 
28         private void button1_Click(object sender, EventArgs e)
29         {
30             this.timer1.Enabled = true;
31         }
32 
33         private void button2_Click(object sender, EventArgs e)
34         {
35             this.timer1.Enabled = false;
36         }
37 
38     }
39 }
View Code

 

设计闪烁的窗体

标签:

原文地址:http://www.cnblogs.com/net064/p/5664437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!