Mainly hereUse the API function Animate Window to achieve the form left, right, up, down, expand, fade in sliding or scrolling animation effects, the steps are as follows:
1. Create a new form and use 2 GroupBox controls.
2. Add 2 RadioButton controls in Control 1, and set Text to "Scroll Form" and "Sliding Form" respectively, and set the former Checked to True.
3. Add 6 buttons in Space 2, the Text is "Anime from left to right", "Anime from right to left", "Anime from top to bottom", "Anime from bottom to top", "Anime from bottom to top", "Expand animation outward", and "Fake into animated form".
4. Add a new Window form and set Text to "Animated Form". Set its "BackgroundImage" property, import an image to be loaded, and then set its "BackgroundImageLayout" property to "Stretch".
5. The main codes of each button event are as follows:
private void button1_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if ( == true)
{
= "Scroll the form animation effect from left to right";
}
else
{
= "Slide the form animation effect from left to right";
}
();
}
private void button4_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if ( == true)
{
= "Scroll the form animation effect from right to left";
}
else
{
= "Slide the form animation effect from right to left";
}
();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if ( == true)
{
= "Scroll the form animation effect from top to bottom";
}
else
{
= "Slide the form animation effect from top to bottom";
}
();
}
private void button5_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if ( == true)
{
= "Scroll the form animation effect from bottom to top";
}
else
{
= "Slide the form animation effect from bottom to top";
}
();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
= "Extend form animation effect outward";
();
}
private void button6_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
= "Fake in form animation effect";
();
}
6. Double-click the Form2 form to enter the code view. First, define common variables, the specific code is as follows:
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;
[("")]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime,int dwFlags);
7. The following adds load event code to the Form2 form, as follows:
private void Form2_Load(object sender, EventArgs e)
{
if ( == "Scroll the form animation effect from left to right")
{
AnimateWindow(,2000,AW_HOR_POSITIVE);
}
if ( == "Swipe the form animation effect from left to right")
{
AnimateWindow(, 2000, AW_SLIDE+AW_HOR_POSITIVE);
}
if ( == "Scroll form animation effect from right to left")
{
AnimateWindow(, 2000, AW_HOR_NEGATIVE);
}
if ( == "Slide form animation effect from right to left")
{
AnimateWindow(, 2000, AW_SLIDE + AW_HOR_NEGATIVE);
}
if ( == "Scroll the form animation effect from top to bottom")
{
AnimateWindow(, 2000, AW_VER_POSITIVE);
}
if ( == "Swipe the form animation effect from top to bottom")
{
AnimateWindow(, 2000, AW_SLIDE + AW_VER_POSITIVE);
}
if ( == "Scroll the form animation effect from bottom to top")
{
AnimateWindow(, 2000, AW_VER_NEGATIVE);
}
if ( == "Slide the form animation effect from bottom to top")
{
AnimateWindow(, 2000, AW_SLIDE + AW_VER_NEGATIVE);
}
if ( == "Extend form animation effect outward")
{
AnimateWindow(, 2000, AW_SLIDE + AW_CENTER);
}
if ( == "Fake in form animation effect")
{
AnimateWindow(, 2000, AW_BLEND);
}
}//yinyiniao's Blog
1. Create a new form and use 2 GroupBox controls.
2. Add 2 RadioButton controls in Control 1, and set Text to "Scroll Form" and "Sliding Form" respectively, and set the former Checked to True.
3. Add 6 buttons in Space 2, the Text is "Anime from left to right", "Anime from right to left", "Anime from top to bottom", "Anime from bottom to top", "Anime from bottom to top", "Expand animation outward", and "Fake into animated form".
4. Add a new Window form and set Text to "Animated Form". Set its "BackgroundImage" property, import an image to be loaded, and then set its "BackgroundImageLayout" property to "Stretch".
5. The main codes of each button event are as follows:
Copy the codeThe code is as follows:
private void button1_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if ( == true)
{
= "Scroll the form animation effect from left to right";
}
else
{
= "Slide the form animation effect from left to right";
}
();
}
private void button4_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if ( == true)
{
= "Scroll the form animation effect from right to left";
}
else
{
= "Slide the form animation effect from right to left";
}
();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if ( == true)
{
= "Scroll the form animation effect from top to bottom";
}
else
{
= "Slide the form animation effect from top to bottom";
}
();
}
private void button5_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
if ( == true)
{
= "Scroll the form animation effect from bottom to top";
}
else
{
= "Slide the form animation effect from bottom to top";
}
();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
= "Extend form animation effect outward";
();
}
private void button6_Click(object sender, EventArgs e)
{
Form2 myf = new Form2();
= "Fake in form animation effect";
();
}
6. Double-click the Form2 form to enter the code view. First, define common variables, the specific code is as follows:
Copy the codeThe code is as follows:
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;
[("")]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime,int dwFlags);
7. The following adds load event code to the Form2 form, as follows:
Copy the codeThe code is as follows:
private void Form2_Load(object sender, EventArgs e)
{
if ( == "Scroll the form animation effect from left to right")
{
AnimateWindow(,2000,AW_HOR_POSITIVE);
}
if ( == "Swipe the form animation effect from left to right")
{
AnimateWindow(, 2000, AW_SLIDE+AW_HOR_POSITIVE);
}
if ( == "Scroll form animation effect from right to left")
{
AnimateWindow(, 2000, AW_HOR_NEGATIVE);
}
if ( == "Slide form animation effect from right to left")
{
AnimateWindow(, 2000, AW_SLIDE + AW_HOR_NEGATIVE);
}
if ( == "Scroll the form animation effect from top to bottom")
{
AnimateWindow(, 2000, AW_VER_POSITIVE);
}
if ( == "Swipe the form animation effect from top to bottom")
{
AnimateWindow(, 2000, AW_SLIDE + AW_VER_POSITIVE);
}
if ( == "Scroll the form animation effect from bottom to top")
{
AnimateWindow(, 2000, AW_VER_NEGATIVE);
}
if ( == "Slide the form animation effect from bottom to top")
{
AnimateWindow(, 2000, AW_SLIDE + AW_VER_NEGATIVE);
}
if ( == "Extend form animation effect outward")
{
AnimateWindow(, 2000, AW_SLIDE + AW_CENTER);
}
if ( == "Fake in form animation effect")
{
AnimateWindow(, 2000, AW_BLEND);
}
}//yinyiniao's Blog