接着上一篇使用的是XAML来实现动画的效果,今天我们用代码来实现下:

我们在窗体上放一个Rectangle,对这个Rectangle实现宽度的变化。当我们按下按钮来触发它的宽度变化。

object sender, RoutedEventArgs e) { DoubleAnimation doubleAnimation = new DoubleAnimation(); doubleAnimation.From = 0; doubleAnimation.To = 60; //TimeSpan时间的绝对值 doubleAnimation.Duration =new Duration(new TimeSpan(0,0,0,3)); //无限次重复 doubleAnimation.RepeatBehavior = RepeatBehavior.Forever; //按相反的顺序播放 doubleAnimation.AutoReverse = true; //启动动画,并把变化赋给宽度 rectangle1.BeginAnimation(Rectangle.WidthProperty,doubleAnimation); }

相关文章:

  • 2021-10-01
  • 2021-10-31
  • 2022-01-21
  • 2021-06-03
  • 2021-09-15
  • 2021-09-10
  • 2021-09-06
  • 2021-10-12
猜你喜欢
  • 2021-06-17
  • 2021-05-27
  • 2021-09-08
  • 2022-02-17
  • 2021-12-28
  • 2021-11-29
  • 2022-01-26
相关资源
相似解决方案