惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
罗磊的独立博客
SecWiki News
SecWiki News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
IT之家
IT之家
博客园 - 聂微东
T
The Exploit Database - CXSecurity.com
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Vercel News
Vercel News
G
GRAHAM CLULEY
D
DataBreaches.Net
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
T
Tenable Blog
Spread Privacy
Spread Privacy
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
J
Java Code Geeks
博客园 - Franky
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
Threatpost
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
U
Unit 42
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
K
Kaspersky official blog
有赞技术团队
有赞技术团队
B
Blog
腾讯CDC

博客园 - 云梦鸿

Winform界面显示的“语言”切换 Linux使用笔记 QT 练习笔记 QT 读写配置文件(*.INI) ubuntu 配置网口静态IP C++ 读写文件 C#编写Windows服务 C#代码计算农历(日期、节气、节日) 中标麒麟,使用笔记 关于无密码访问 Windows7/10 的远程桌面/共享 颜色转换:HSB颜色 与 RGB颜色 QT 信号(槽)绑定的使用_connect QT 给控件(Label)设置显示图片 QT 打包Windows应用程序(*.exe) C#程序执行Python脚本 C#监控U盘插拔 C# GetWindowRect 获取窗体在屏幕中的位置信息 C# 创建音频WAVE文件头信息(*.wav) VS2019错误:CS8370 的处理方法
C# AnimateWindow 设置窗体动画
云梦鸿 · 2020-12-24 · via 博客园 - 云梦鸿

使用Win32的API接口,实现的窗口动画:淡入淡出、中心展开或收缩、滑动滚入或滚出。

      bool AnimateWindow(IntPtr hWnd, int dwTime, int dwFlags);

编写如下代码:

        /// <summary>
        /// 从左到右滚动窗口,与AW_SLIDE一起时变成滑动效果。
        /// <para>This flag is ignored  when used with AW_CENTER or AW_BLEND.</para>
        /// </summary>
        public const Int32 AW_HOR_POSITIVE = 0x00000001;
        /// <summary>
        /// 从右到左滚动窗口,与AW_SLIDE一起时变成滑动效果。
        /// <para>This flag is ignored  when used with AW_CENTER or AW_BLEND.</para>
        /// </summary>
        public const Int32 AW_HOR_NEGATIVE = 0x00000002;
        /// <summary>
        /// 从上到下滚动窗口,与AW_SLIDE一起时变成滑动效果。
        /// <para>This flag is ignored  when used with AW_CENTER or AW_BLEND.</para>
        /// </summary>
        public const Int32 AW_VER_POSITIVE = 0x00000004;
        /// <summary>
        /// 从下到上滚动窗口,与AW_SLIDE一起时变成滑动效果。
        /// <para>This flag is ignored  when used with AW_CENTER or AW_BLEND.</para>
        /// </summary>
        public const Int32 AW_VER_NEGATIVE = 0x00000008;
        /// <summary>
        /// 使用滑动效果。不单独使用,与方向滚动组合使用。
        /// <para>This flag is ignored  when used with AW_CENTER.</para>
        /// </summary>
        public const Int32 AW_SLIDE = 0x00040000;
        /// <summary>
        /// 在中间缩放窗口。中心向四周展开,或向中心收缩关闭。
        /// </summary>
        public const Int32 AW_CENTER = 0x00000010;
        /// <summary>
        /// 使用淡入淡出效果(透明度渐变)。只有在hWnd是顶级窗口时,才有效。
        /// </summary>
        public const Int32 AW_BLEND = 0x00080000;
        /// <summary>
        /// 隐藏或关闭窗口
        /// </summary>
        public const Int32 AW_HIDE = 0x00010000;
        /// <summary>
        /// 激活或加载窗口(不可与AW_HIDE一起使用)
        /// </summary>
        public const Int32 AW_ACTIVATE = 0x00020000;

        /// <summary>
        /// 设置窗口动画效果
        /// </summary>
        /// <param name="hWnd">窗口的句柄</param>
        /// <param name="dwTime">动画时间(毫秒)</param>
        /// <param name="dwFlags">动画样式(AW)标识</param>
        /// <returns></returns>
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool AnimateWindow(IntPtr hWnd, int dwTime, int dwFlags);

在窗口的Load处理事件中调用方法:

private void Form1_Load(objec sender, EventArgs e)
{
    AnimateWindow(this.Handle, 2000, AW_ACTIVATE | AW_CENTER)  // 实现在窗口范围的中心向四周散开,加载窗口
}

同样的,在FormClosing处理事件中,调用方法,可以实现在窗口关闭时的动画效果。