using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; namespace Implab.Fx { public static class AnimationHelpers { public static Animation AnimateProperty(this Animation animation, Action setter, Func getter, TVal newValue, Func fx) where TTarget: class { if (animation == null) throw new ArgumentNullException("animation"); TVal oldValue = getter(animation.Traget); animation.Step += (target, elaped, duration) => { var value = fx(oldValue, newValue, elaped, duration); setter(target, value); }; return animation; } public static Animation
AnimateTransparency(this Form ctl, float newValue) { var anim = new Animation(ctl); anim.AnimateProperty( (target, value) => target.Opacity = value, target => target.Opacity, newValue, (ov, nv, el, du) => ov + ((float)el / du) * (nv - ov) ); return anim; } } }