WinForm special effect: make the two forms have activation effect at the same time, winform form
Windows api. When a form is activated, a message is sent to another api.
[Csharp]View plaincopy
- Using System;
- Using System. Windows. Forms;
- Using System. Runtime. InteropServices;
- Namespace WindowsApplication43
- {
- Public partial class Form1: Form
- {
- Form frm = null;
- Public Form1 ()
- {
- InitializeComponent ();
- This. Activated + = Form_Activated;
- }
- Const int WM_NCACTIVATE = 0x86;
- Const int WA_ACTIVE = 0x1;
- [DllImport ("user32.dll", EntryPoint = "SendMessage")]
- Public static extern int SendMessage (IntPtr hWnd, int wMsg, int wParam, int lParam );
- Private void button#click (object sender, EventArgs e)
- {
- Frm = new Form ();
- Frm. Text = "jinjazz ";
- Frm. Activated + = Form_Activated;
- Frm. Show ();
- Frm. Location = new System. Drawing. Point (this. Left + this. Width, this. Top );
- SendMessage (this. Handle, WM_NCACTIVATE, WA_ACTIVE, 0 );
- }
- Void Form_Activated (object sender, EventArgs e)
- {
- SendMessage (this. Handle, WM_NCACTIVATE, WA_ACTIVE, 0 );
- If (frm! = Null)
- SendMessage (frm. Handle, WM_NCACTIVATE, WA_ACTIVE, 0 );
- }
- }
- }