c# Winform 缓动动画
一、定义缓动动画类
public class AnimationHelper
{
Timer animationTimer = new Timer();
double velocity = 0.0;
Point location = Point.Empty;
double force = 0.01; //0.69;
double drag = 0.8;
private Control control;
//private AxShockwaveFlash control;
private int targetPos=0; public AnimationHelper(int interval=5)
{
animationTimer.Interval = interval;
animationTimer.Tick += delegate
{
if (control == null) return;
int currentPos = control.Location.X;
if (Math.Abs(currentPos - targetPos) <= 5)
{
control.Location = new Point(targetPos, control.Location.Y);
animationTimer.Stop();
}
int dx = targetPos - currentPos;
velocity += force * dx;
velocity *= drag;
if (Math.Abs(velocity) < 5)
{
if (velocity > 0)
velocity = 5;
else
velocity = -5;
}
control.Location = new Point(currentPos + (int)velocity, control.Location.Y);
};
animationTimer.Start();
} public void MoveXEx(Control control, int targetPos, Action completeWith = null)
{
this.control = control;
this.targetPos = targetPos;
velocity = 0;
animationTimer.Start();
}
}
二、’使用教程:
AnimationHelper animationHelper = new AnimationHelper();
AnimationHelper animationHelper1 = new AnimationHelper();
private int pos = 0;
private int pos1 = 0;
private int dx = 200;
private void button1_Click(object sender, EventArgs e)
{
animationHelper.MoveXEx(pictureBox2, pos += dx);
animationHelper1.MoveXEx(pictureBox1, pos1 += dx); } private void button2_Click(object sender, EventArgs e)
{
animationHelper.MoveXEx(pictureBox2, pos -= dx);
animationHelper1.MoveXEx(pictureBox1, pos1 -= dx);
}
三、效果:
c# Winform 缓动动画的更多相关文章
- jQuery-1.9.1源码分析系列(十五) 动画处理——缓动动画核心Tween
在jQuery内部函数Animation中调用到了createTweens()来创建缓动动画组,创建完成后的结果为: 可以看到上面的缓动动画组有四个原子动画组成.每一个原子动画的信息都包含在里面了. ...
- 背水一战 Windows 10 (15) - 动画: 缓动动画
[源码下载] 背水一战 Windows 10 (15) - 动画: 缓动动画 作者:webabcd 介绍背水一战 Windows 10 之 动画 缓动动画 - easing 示例演示缓动(easing ...
- WPF界面设计技巧(7)—模拟电梯升降的缓动动画
原文:WPF界面设计技巧(7)-模拟电梯升降的缓动动画 如同Flash一样,WPF的亮点之一也在于其擅于表现平滑的动画效果,但以移动动画来说,仅凭简单的起始位置.目标位置,所产生的动画仍会非常生硬,这 ...
- Windows Phone开发(42):缓动动画
原文:Windows Phone开发(42):缓动动画 前面在讨论关键帧动画的时候,我有意把几个带缓动动画的关键帧动画忽略掉,如EasingColorKeyFrame.EasingDoubleKeyF ...
- 重新想象 Windows 8 Store Apps (19) - 动画: 线性动画, 关键帧动画, 缓动动画
原文:重新想象 Windows 8 Store Apps (19) - 动画: 线性动画, 关键帧动画, 缓动动画 [源码下载] 重新想象 Windows 8 Store Apps (19) - 动画 ...
- JS基础知识——缓动动画
基于距离的缓动动画 原理:设定起始位置 start 和终止位置 end,变化会越来越慢. 公式:start=start+(end-start)/10; 这个10不是固定的,想分成多少份就分成 ...
- JS-特效 ~ 04. client对象、网页可视区域的宽高、client / offset / scroll 三大家族的区别、冒泡事件、事件委托、获取内嵌式和外链式属性getStyle(ele,attr) ;、缓动动画封装
知识点: 模拟滚动条的解除事件问题 : event内置对象,包含 了大量事件: page兼容性: pageX || clientX + scool().top : if (true === a)tr ...
- js简单动画:匀速动画、缓动动画、多物体动画以及透明度动画
主要实现以下几种简单的动画效果(其实原理基本相同): 1.匀速动画:物体的速度固定 2.缓动动画:物体速度逐渐变慢 3.多物体动画 4.透明度动画 效果实现: 1.匀速动画(以物体左右匀速运动为例) ...
- js off 缓动动画
动画也有很多种,一起来学习,缓动动画吧 缓动动画 1.缓动动画原理=盒子位置+(目标盒子位置-现在盒子位置)/10 2.步长越来越小 3.让步长越来越小的公式 步长=(目标位置-本身位置)/ ...
- JS实现缓动动画效果
原理如下: 假设要从数值A变化到数值B,如果是线性运动,则每次移动距离是一样:如果是缓动,每次移动距离不一样.那如何才能不一样呢?很简单,按比例移动就可以. 例如:每次移动剩余距离的一半. 对吧,超容 ...
随机推荐
- 定时任务,LocalDateTime,在代码中调用其他项目的接口url
1.定时任务 1.在类上添加注解 @Component @Configuration @EnableScheduling 2.在类中方法上添加注解 @Scheduled(cron = "0 ...
- Linux备份服务
备份服务 一.备份服务概述 备份服务:需要使用脚本,打包备份,定时任务 通过rsyncd服务,不同主机之间进行数据传输 rsyncd特点: rsync是个服务,也是命令 使用方便,有多种模式 传输数据 ...
- FAQ Selenium中提示can not connect to the service chromedriver 的解决方法
can not connect to the service chromedriver问题的处理 背景 一个同学反馈运行如下代码 from selenium import webdriver ...
- 使用Navicat操作MySQL数据库
一.Navicat连接数据库 ①进入Navicat,由于要使用的是MySQL数据库,选择MySQL ②输入连接名(这个是随便起的) 由上图可知连接数据库的四个要素 host:确定要操作的数据库在哪台电 ...
- P32_全局配置 - tabBar
什么是 tabBar tabBar 是移动端应用常见的页面效果,用于实现多页面的快速切换.小程序中通常将其分为: 底部 tabBar 顶部 tabBar 注意:tabBar中只能配置最少 2 个.最多 ...
- .NET Core MongoDB的简单使用
一.创建测试库.测试表.添加测试数据 使用之前文章提到的MongoDB Compass用法分别添加数据库[myDb]和集合(表)[userinfos]信息, 参考链接为:MongoDB Compass ...
- STM32F0库函数初始化系列:ADC
static void ADC_Config(void) { ADC_InitTypeDef ADC_InitStructure; /* ADCs DeInit */ //ADC_DeInit(ADC ...
- jquery(四:jquery的事件、Ajax)
Jquery事件 jQuery注册事件 1.利用原生的js来为对象注册事件,后面的会把前面的覆盖 2.用jQuery的$()来为对象注册事件,后面不会把前面的覆盖 简单事件绑定-----click() ...
- Zstack私有云平台运行实践
很高兴昨天加了大名鼎鼎的杰杰站长的微信,系统运行的怎么样,一定不能只是给力两个字完事,下面就上具体的: 经过这几年的运行费和预研经费的支持,组里除了在线的几台服务器外,慢慢离线也积攒了几台用作调试和做 ...
- C++梳理
1.基础篇 1.C++ 中的四种智能指针 为什么要使⽤智能指针:智能指针其作⽤是管理⼀个指针,避免程序员申请的空间在函数结束时忘记释放,造成内存泄漏这种情况的发⽣.使⽤智能指针可以很⼤程度上的避免这个 ...