一、定义缓动动画类

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);
}

三、效果:

最新文章

  1. pod Spec管理配置
  2. export a java project to runable jar
  3. python数据结构-基本数据类型
  4. Rose
  5. 关键字throw(something)限制
  6. python - socket练习(输入系统命令)
  7. 性能优化工具---iostat
  8. boost.xml_parser中文字符问题
  9. BZOJ 1975 SDOI2010 魔法猪学院 A*k短路
  10. UVa 572 Oil Deposits(DFS)
  11. 使用KindEditor富文本编辑器,点击批量上传按钮没有选择图片按钮
  12. js关于setTimeout传参
  13. 文档发布工具mkdocs
  14. 什么是Servlet(原理,从访问到方法)
  15. Python descriptor 以及 内置property()函数
  16. Nokia Imaging SDK
  17. $思维导图——numpy基本知识
  18. 安装了IntelliJ IDEA中文输入法光标不跟随处理办法
  19. HDU 4609 FFT模板
  20. HDU 1238 Substing

热门文章

  1. 问题记录:VMware vSphere vCenter 7.0 上传文件失败
  2. 11月15日内容总结——软件开发架构、网络编程介绍和OSI七层协议介绍
  3. 10月25日内容总结——正则表达式相关知识与re模块
  4. 翻译《threejsfundamentals》离屏渲染+web-worker一篇
  5. Eclpis-cannot open git-receive-pack
  6. xml基本学习
  7. STM32F0库函数初始化系列:PWM输出
  8. 软赢软件控制器在Zstack云主机实现电机控制的方法
  9. 使用Docker搭建EPICS的IOC记录
  10. 学习ASP.NET Core Blazor编程系列二十七——JWT登录(1)