Start the form as an animation

Source: Internet
Author: User

Generally, after an application is started, the normal application window is instantly displayed on the screen. have you ever imagined a scenario where the display of a window is as unpredictable and colorful as a slide? You may not be able to entertain yourself.

Now you can think of a screen like this: When you start an application, a small dot appears in the center of the monitor, and then grows slowly and scales around, until all windows are displayed. and when you close it, it will slowly disappear from the display from top down .... what is the effect? Well, if you want to, follow me to fulfill such a great dream.

What is the design idea? If you are smart, you will immediately realize that this project is likely to use Windows APIs. when I check the Internet, there is indeed a function: animatewindow, which can achieve the animation effect of the form. so the rest of the work is to view msdn and learn more about the animatewindow function.

The following describes the application of the animatewindow function in C # in combination with this example.

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);
}
}
}

Note: although it is a small skill, there are a lot of ideas, you can have a high eye, but the hands must be at the bottom.

From: http://www.cnblogs.com/ziyiFly/archive/2008/09/18/1293327.html

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.