1. Overview
When the QQ dialog box receives a message, if the dialog box is not the active form, the dialog box flashes to prompt the user for a new message that needs to be read, and this is the form in which the Flash form is implemented.
2. Design details
. NET does not provide the classes and methods that implement the flicker of the form directly, it needs to call the Windows API function FlashWindow () implementation. The function is declared in C # as follows:
[DllImport ("user32")]
private static extern long FlashWindow (IntPtr handle,bool binvert);
This function can implement a form flicker, but only once, if you want to achieve multiple flashes, you can use the Timer Timer component implementation.
Note: When using Windows API functions in Windows applications, namespace System.Runtime.InteropServices must be introduced;
3. Form Design
4. Program code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Windows.Forms;9 usingSystem.Runtime.InteropServices;Ten One namespaceKaifafanli A { - - Public Partial classForm6:form the { -[DllImport ("User32")] - Private Static extern LongFlashWindow (INTPTR handle,BOOLBinvert); - PublicFORM6 () + { - InitializeComponent (); + } A at Private voidTimer1_Tick (Objectsender, EventArgs e) - { -FlashWindow ( This. Handle,true); - } - - Private voidButton1_Click (Objectsender, EventArgs e) in { - This. timer1. Enabled =true; to } + - Private voidButton2_Click (Objectsender, EventArgs e) the { * This. timer1. Enabled =false; $ }Panax Notoginseng - } the}
View Code
Design a flashing form