c#之利用API函数实现动画窗体的方法详解
时间:2022-12-07 04:43:24
这里主要利用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#,API函数,动画窗体
0
投稿
猜你喜欢
C#文件流读写和进度回调示例详解
2022-08-12 14:52:31
Java实现计算器设计
2023-08-18 13:36:54
C#读写xml文件方法总结(超详细!)
2023-11-23 13:16:40
java时区转换的理解及示例详解
2022-01-19 08:35:20
WPF ProgressBar实现实时进度效果
2023-01-14 08:05:49
C#实现餐厅管理系统
2023-11-27 16:05:05
Java编程实现基于TCP协议的Socket聊天室示例
2023-02-17 17:23:13
sqlite数据库的介绍与java操作sqlite的实例讲解
2023-05-09 03:07:40
JAVA代码实现MongoDB动态条件之分页查询
2022-05-21 12:44:11
关于C++虚继承的内存模型问题
2023-04-01 06:10:21
C#将制定目录文件名转换成大写的方法
2022-10-03 19:46:36
Android利用Canvas类绘制图形
2022-09-17 14:22:02
java微信支付接入流程详解
2023-07-28 18:37:46
Android实现加载圈
2023-03-27 16:44:34
Android中activity从创建到显示的基本介绍
2023-01-08 02:07:41
java中文传值乱码问题的解决方法
2023-11-25 16:26:47
java web监听器统计在线用户及人数
2023-12-14 14:42:52
SpringBoot整合jersey的示例代码
2021-08-28 05:23:12
spring boot 动态生成接口实现类的场景分析
2022-12-14 05:09:33
Android编程实现图片的浏览、缩放、拖动和自动居中效果
2021-06-04 15:01:39