Use the AnimateWindow API function to implement an animation form

Source: Internet
Author: User

Declaration method:

Statement
[DllImportAttribute ("user32.dll")]
Private static extern bool AnimateWindow (IntPtr hwnd, int dwTime, int dwFlags );

Parameter description:

Code
(1). IntPtr hwnd: The Handle object of the target window, usually this. Handle
(2). int dwTime: animation duration. The longer the value is, the longer the animation effect.
(3). int dwFlags: Specifies the animation effect type option. It is declared as follows in C:
Note: you only need to declare the required animation type in your program. The meaning of each parameter will be described in detail later.
Public const Int32 AW_HOR_POSITIVE = 0x00000001;
Public const Int32 AW_HOR_NEGATIVE = 0x00000002;
Public const Int32 AW_VER_POSITIVE = 0x00000004;
Public const Int32 AW_VER_NEGATIVE = 0x00000008;
Public const Int32 AW_CENTER = 0x00000010;
Public const Int32 AW_HIDE = 0x00010000;
Public const Int32 AW_ACTIVATE = 0x00020000;
Public const Int32 AW_SLIDE = 0x00040000;
Public const Int32 AW_BLEND = 0x00080000;

Animation effect types:

1. AW_SLIDE: This type is used by default. This type is ignored when the AW_CENTER effect is used.

2. AW_ACTIVE: Activation window. This effect cannot be used when AW_HIDE effect is used.

3. AW_BLEND: fade-in effect

4. AW_HIDE: Hide the window

5. AW_CENTER: when used with the AW_HIDE effect, the effect overlaps the number of windows, and the window is extended separately.

6. AW_HOR_POSITIVE: display the window from left to right

7. AW_HOR_NEGATIVE: display window from right to left

8. AW_VER_POSITVE: display window from top to bottom

9. AW_VER_NEGATIVE: display the window from bottom to top

After understanding this, our work will become very simple.

After the program is started, the code of the animation display window is as follows:

Code
AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_CENTER);

After the program is closed, the animation display window code is as follows:

Code
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
      AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);
    }

The complete code of the program is as follows:

Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FalshWindows
{
  public partial class Form1 : Form
  {
    [DllImportAttribute("user32.dll")]
    private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
    public const Int32 AW_HOR_POSITIVE = 0x00000001;
    public const Int32 AW_HOR_NEGATIVE = 0x00000002;
    public const Int32 AW_VER_POSITIVE = 0x00000004;
    public const Int32 AW_VER_NEGATIVE = 0x00000008;
    public const Int32 AW_CENTER = 0x00000010;
    public const Int32 AW_HIDE = 0x00010000;
    public const Int32 AW_ACTIVATE = 0x00020000;
    public const Int32 AW_SLIDE = 0x00040000;
    public const Int32 AW_BLEND = 0x00080000;
    public Form1()
    {
      InitializeComponent();
      AnimateWindow(this.Handle, 1000, AW_SLIDE + AW_CENTER);
    }
    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
      AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);
    }
  }
}

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.