-
C#教程之c#之利用API函数实现动画窗体的方法详解
这里主要利用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
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
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式