这里主要
利用api函数animate window实现窗体左右,上下,扩展,淡入滑动或滚动动画效果,步骤如下:
1.新建窗体,使用2个groupbox控件。
2.在控件1中添加2个radiobutton控件,并设置text分别为“滚动窗体”,“滑动窗体”,并使前者checked设置为true。
3.在空间2中添加6个按钮,text分别为“自左向右动画”,“自右向左动画”,“自上向下动画”,“自下向上动画”,“向外扩展动画”,“淡入动画窗体”。
4.添加一新的window窗体,设置text为“动画窗体”。设置其“backgroundimage”属性,导入一张要加载的图像,然后设置其“backgroundimagelayout”属性为“stretch”。
5.各按钮事件主要代码如下:
private void button1_click(object sender, eventargs e)
{
form2 myf = new form2();
if (radiobutton1.checked == true)
{
myf.text = "自左向右滚动窗体动画效果";
}
else
{
myf.text = "自左向右滑动窗体动画效果";
}
myf.show();
}
private void button4_click(object sender, eventargs e)
{
form2 myf = new form2();
if (radiobutton1.checked == true)
{
myf.text = "自右向左滚动窗体动画效果";
}
else
{
myf.text = "自右向左滑动窗体动画效果";
}
myf.show();
}
private void button2_click(object sender, eventargs e)
{
form2 myf = new form2();
if (radiobutton1.checked == true)
{
myf.text = "自上向下滚动窗体动画效果";
}
else
{
myf.text = "自上向下滑动窗体动画效果";
}
myf.show();
}
private void button5_click(object sender, eventargs e)
{
form2 myf = new form2();
if (radiobutton1.checked == true)
{
myf.text = "自下向上滚动窗体动画效果";
}
else
{
myf.text = "自下向上滑动窗体动画效果";
}
myf.show();
}
private void button3_click(object sender, eventargs e)
{
form2 myf = new form2();
myf.text = "向外扩展窗体动画效果";
myf.show();
}
private void button6_click(object sender, eventargs e)
{
form2 myf = new form2();
myf.text = "淡入窗体动画效果";
myf.show();
}
6.双击form2窗体,进入代码视图。首先定义公用变量,具体代码如下:
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;
[system.runtime.interopservices.dllimportattribute("user32.dll")]
private static extern bool animatewindow(intptr hwnd,int dwtime,int dwflags);
7.下面为form2窗体添加加载事件代码,具体如下:
private void form2_load(object sender, eventargs e)
{
if (this.text == "自左向右滚动窗体动画效果")
{
animatewindow(this.handle,2000,aw_hor_positive);
}
if (this.text == "自左向右滑动窗体动画效果")
{
animatewindow(this.handle, 2000, aw_slide+aw_hor_positive);
}
if (this.text == "自右向左滚动窗体动画效果")
{
animatewindow(this.handle, 2000, aw_hor_negative);
}
if (this.text == "自右向左滑动窗体动画效果")
{
animatewindow(this.handle, 2000, aw_slide + aw_hor_negative);
}
if (this.text == "自上向下滚动窗体动画效果")
{
animatewindow(this.handle, 2000, aw_ver_positive);
}
if (this.text == "自上向下滑动窗体动画效果")
{
animatewindow(this.handle, 2000, aw_slide + aw_ver_positive);
}
if (this.text == "自下向上滚动窗体动画效果")
{
animatewindow(this.handle, 2000, aw_ver_negative);
}
if (this.text == "自下向上滑动窗体动画效果")
{
animatewindow(this.handle, 2000, aw_slide + aw_ver_negative);
}
if (this.text == "向外扩展窗体动画效果")
{
animatewindow(this.handle, 2000, aw_slide + aw_center);
}
if (this.text == "淡入窗体动画效果")
{
animatewindow(this.handle, 2000, aw_blend);
}
}//yinyiniao's blog
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
C#实现猜数字游戏
本文实例为大家分享了c#实现猜数字游戏具体代码,供大家参考,具体内容如下给定一个0-100的随机数字猜其大小题目样式:电脑产生一个0到100之间的随机数字,并且...
[阅读全文]
-
-
C# 可空类型的具体使用
在项目中我们经常会遇到可为空类型,那么到底什么是可为空类型呢?下面我们将从4个方面为大家剖析。1、可空类型基础知识顾名思义,可空类型指的就是某个对象类型可以为空...
[阅读全文]
-
-
-
C#实现猜数字小游戏
本文实例为大家分享了c#实现猜数字小游戏的具体代码,供大家参考,具体内容如下效果如图:代码:using system;using system.collecti...
[阅读全文]
-
-
C#实现简单俄罗斯方块
最近在看《.net游戏编程入门经典 c#篇》 第一章介绍了如何制作俄罗斯方块,自己试了试按照书上的步骤,可算是完成了。于是写下这篇文章留作纪念。1.类的设计在充...
[阅读全文]
-
网友评论