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 );
- }
- }
- }
Winform form mobile event simultaneously moves two forms
Add the following code to the cs code of Form1:
Public Form2 f2 = new Form2 (); // outside the processing function, the global variable
F2.Show (); // call this statement if needed to display Form2
// In this way, f2 is like a component in Form1.
Add the following code to the Form1 mobile event:
Try
{
Int x = f2.Top-this. Top; // calculates the vertical distance between the two boxes.
Int y = f2.Left-this. Left; // calculates the horizontal distance between the two boxes.
F2.Top = this. Top + x;
F2.Left = this. Left + y;
// Fixed the issue. The location of the two boxes in the lower floor is limited ..
} Catch {}
C # winform: the fade-in effect is implemented for the form, but how is the fade-out effect implemented?
// Overwrite the form close event
Protected override void OnClosing (CancelEventArgs e)
{
E. Cancel = true;
Timer2.Start ();
}
Private void timer2_Tick (object sender, EventArgs e)
{
This. OPS-= 0.1;
}
Tested. Timer is added separately.
(You have answered in another post. When you click Close, the form fades out .)