WinForm special effect: make the two forms have activation effect at the same time, winform form

Source: Internet
Author: User

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
  1. Using System;
  2. Using System. Windows. Forms;
  3. Using System. Runtime. InteropServices;
  4. Namespace WindowsApplication43
  5. {
  6. Public partial class Form1: Form
  7. {
  8. Form frm = null;
  9. Public Form1 ()
  10. {
  11. InitializeComponent ();
  12. This. Activated + = Form_Activated;
  13. }
  14. Const int WM_NCACTIVATE = 0x86;
  15. Const int WA_ACTIVE = 0x1;
  16. [DllImport ("user32.dll", EntryPoint = "SendMessage")]
  17. Public static extern int SendMessage (IntPtr hWnd, int wMsg, int wParam, int lParam );
  18. Private void button#click (object sender, EventArgs e)
  19. {
  20. Frm = new Form ();
  21. Frm. Text = "jinjazz ";
  22. Frm. Activated + = Form_Activated;
  23. Frm. Show ();
  24. Frm. Location = new System. Drawing. Point (this. Left + this. Width, this. Top );
  25. SendMessage (this. Handle, WM_NCACTIVATE, WA_ACTIVE, 0 );
  26. }
  27. Void Form_Activated (object sender, EventArgs e)
  28. {
  29. SendMessage (this. Handle, WM_NCACTIVATE, WA_ACTIVE, 0 );
  30. If (frm! = Null)
  31. SendMessage (frm. Handle, WM_NCACTIVATE, WA_ACTIVE, 0 );
  32. }
  33. }
  34. }

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 .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.