zoukankan      html  css  js  c++  java
  • 设计闪烁的窗体

    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
  • 相关阅读:
    【题解】Luogu P2081 [NOI2012]迷失游乐园
    【题解】Luogu P4436 [HNOI/AHOI2018]游戏
    【题解】Luogu P4438 [HNOI/AHOI2018]道路
    【题解】Luogu P1344 [USACO4.4]追查坏牛奶Pollutant Control
    【题解】Luogu P3674 小清新人渣的本愿
    Mysql之数据库存储引擎
    Linux之取消别名设置
    Linux之别名设置
    Mysql之设置用户指定ip地址操作数据库
    Linux之php编译安装5.6
  • 原文地址:https://www.cnblogs.com/net064/p/5664437.html
Copyright © 2011-2022 走看看