http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 4112|回复: 2

[Winform] Winform实现Control移动的效果

[复制链接]
发表于 2013-10-17 20:52:48 | 显示全部楼层 |阅读模式
本帖最后由 Koson 于 2013-10-17 20:54 编辑

虽然几年没有写过Winform code,恰巧这几天在弄一个项目,想要实现淡入淡出的效果。但是一google发现,在Winform中似乎只有窗体(Form)才能实现那效果。无奈,只好改一改思路,随便弄个控件移动的效果来体现一下动态效果了。直接看代码吧:
[code=csharp]/// <summary>
///  Let Control move to special position
///  Create By:Koson
///  Create DT:2013/10/14
///  Update By:
/// </summary>
/// <param name=""></param>
private void slideToDestinationWithSpeed(Control destination, Control control, int delay, int speed, Action onFinish)
        {
            new Task(() =>
            {
                int directionX = destination.Left > control.Left ? speed : -speed;
                int directionY = destination.Bottom > control.Top ? speed : -speed;

                while (control.Left != destination.Left || control.Top != destination.Bottom)
                {
                    try
                    {
                        if (control.Left != destination.Left)
                        {
                            this.Invoke((Action)delegate()
                            {
                                control.Left += directionX;

                                //Add By:Koson
                                //Add Dt:2013/10/17
                                if (control.Left > 3000 || control.Left < -3000)
                                {
                                    control.Left = destination.Left;
                                }

                            });
                        }
                        if (control.Top != destination.Bottom)
                        {
                            this.Invoke((Action)delegate()
                            {
                                control.Top += directionY;
                            });
                        }
                        Thread.Sleep(delay);
                    }
                    catch
                    {
                        // put your code here
                        break;
                    }
                }

                if (onFinish != null) {

                    this.Invoke((Action)delegate() {
                        onFinish();
                    });

                };

            }).Start();
        }[/code]

这样子可以实现简单的移动效果,如果是在比较短的距离内,这样子来实现动态效果还是稍微能感觉的到,比直接Hide=Visible更有体验。也可以用他来实现图片轮播的效果。当然,代码的逻辑可能还需要小小改动问题不大,简单记录下来。

QQ截图20131017205051.jpg

鼠标移到左下角小黑板上,右边的PopWindow缓慢移出,有比较好的体验不hi感到生硬。


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-10-18 08:02:39 | 显示全部楼层
强烈支持楼主ing……
发表于 2013-10-21 16:30:18 | 显示全部楼层
支持楼主!{:soso_e130:}
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-6-1 18:06

© 2014-2021

快速回复 返回顶部 返回列表