C # Call the API function to add dynamic effects to the Winform

Source: Internet
Author: User

To make your Winform more dazzling and beautiful, it is far from enough to have beautiful static parts such as the C # skin and background textures, you also need some dynamic support to make your program interface have a better user experience.

 

Here we will introduce how to call the API functions in user32.dll to add dynamic effects to the Winform interface. User32.dll is an application interface related to the Windows user interface. It is used to include features such as Windows processing and basic user interface, such as window creation and message sending. Like C ++, some API functions in user32 can also be used in C # To develop WINFORM programs.

 

1. Import user32.dll and declare the API function AnimateWindow

// Import user32.dll
[System. Runtime. InteropServices. DllImport ("user32")]
// Declare API functions
Private static extern bool AnimateWindow (IntPtr hwnd, int dwTime, int dwFlags );
 

Description of the three parameters in the AnimateWindow function:

Handle of the control on the hwnd Interface

Duration (1 = 1 millisecond, 1000 = 1 second)

Value of the dwFlags form special effect

 

2. The dwFlags parameter is a constant of the INT type, which defines the specific actions of the special effect.

// Frontend _ horizontal direction
Const int AW_HOR_POSITIVE = 0x0001;
// Negative _ horizontal direction
Const int AW_HOR_NEGATIVE = 0x0002;
// Frontend _ vertical direction
Const int AW_VER_POSITIVE = 0x0004;
// Negative _ vertical direction
Const int AW_VER_NEGATIVE = 0x0008;
// Expand or contract out of the middle four weeks
Const int AW_CENTER = 0x0010;
// Hide the object
Const int AW_HIDE = 0x10000;
// Display object
Const int AW_ACTIVATE = 0x20000;
// Sliding effect
Const int AW_SLIDE = 0x40000;
// Fade in and fade out gradient effect
Const int AW_BLEND = 0x80000;
Of course, when writing code, you can include all the INT values in an enumeration class, which makes it easier to reference them in the program.

 

3. Call the AnimateWindow method in the Program Event to execute the form special effect.

// Animation-the form is zoomed out from the center around until it disappears.
// AW_CENTER | AW_HIDE | AW_HOR_NEGATIVE indicates a set of three special effect states separated by "|", which is similar to calling an API function on C ++.
// This. Handle is the main form Handle, and other controls can also be used.
AnimateWindow (this. Handle, 1000, AW_CENTER | AW_HIDE | AW_HOR_NEGATIVE );
 

4. Here is an example of adding a dynamic special effect to the Winform: Sample

 

Related Article

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.