c#之利用API函数实现动画窗体的方法详解
发布时间:2022-12-07 04:43:24
标签: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)用户
- 本文整理汇总了C#缓存的数据库依赖类SqlCacheDependency的使用方法,具体内容如下:1、数据库依赖类SqlCacheDepen
- 摘要:Java8通过Function获取字段名,解决硬编码,效果类似于mybatis-plus的LambdaQueryWrapper。本文总
- Android 自定义imageview实现图片缩放实例详解 觉得这个自定义的imageview很好用 性能不错 所以
- 本文实例讲述了Spring使用ClassPathResource加载xml资源。分享给大家供大家参考,具体如下:一 代码package le
- spring cloud gateway读取请求参数1. 我的版本:spring-cloud:Hoxton.RELEASEspring-bo
- File存储(内部存储)一旦程序在设备安装后,data/data/包名/ 即为内部存储空间,对外保密。Context提供了2个方法来打开输入
- 我就废话不多说了,大家还是直接看代码吧~ public static void main(String[] args) { &n
- Annotation(注解)是JDK1.5及以后版本引入的。它可以用于创建文档,跟踪代码中的依赖性,甚至执行基本编译时检查。注解是以&
- 前言在mybatis和mybatis plus里,如果你的实体字段是一个枚举类型,而在数据表里是整型,这时在存储时需要进行处理,默认情况下,
- 本文实例讲述了Java线程之守护线程(Daemon)用法。分享给大家供大家参考。具体如下:守护线程(Daemon)Java有两种Thread
- App的小功能点,很简单几十行代码就可以实现主页面代码package com.buildingbuilding;import android
- 1、概述之前写了一个Android * QQ5.0 侧滑菜单效果 自定义控件来袭 ,恰逢QQ5.2又加了一个右侧菜单,刚好看了下Drawe
- 前言在unity的ugui中Text控件,有时我们会有各种各样的需求,比如类似html中css的text-overflow属性,希望一段文字
- 本文实例为大家分享了JavaWeb实现用户登录与注册的具体代码,供大家参考,具体内容如下所用知识客户端:HTML CSS JS (JQuer
- 一 模式介绍重试模式,是应用在异常处理中,发生异常的时候,能够对业务程序进行重新调用,在实际中,可以使用Polly提供稳定,简单的用法,自己
- 一、前言在Spring中,事务有两种实现方式:编程式事务管理: 编程式事务管理使用TransactionTemplate可实现更细
- AssertJ是我目前见过的最强大的断言api,没有之一。官网传送门为什么使用assertJ?1、流式断言,代码即用例,直观易懂。举个例子:
- 我们还是来讨论c++吧,这几年在c++里面玩代码自动生成技术,而预处理是不可避免,也是不可或缺的重要工具。虽然boost pp预处理库在宏的
- MyBatis 的一个强大的特性之一通常是它的动态 SQL 能力。如果你有使用 JDBC 或其他 相似框架的经验,你就明白条件地串联 SQL