标签:strong div ima str public rms wing return width
public partial class ButtonExt : Button { private AnimationTimer _Animation; /// <summary> /// 动画组件对象 /// </summary> [Description("动画组件对象")] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public AnimationTimer Animation { get { return _Animation; } set { _Animation = value; } } protected override Size DefaultSize { get { return new Size(100, 40); } } public ButtonExt() { InitializeComponent(); this.BackColor = System.Drawing.Color.OliveDrab; this.FlatAppearance.BorderSize = 0; this.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.ForeColor = System.Drawing.Color.White; this._Animation = new AnimationTimer(this, new AnimationOptions()); this.Animation.AnimationIng += new AnimationTimer.AnimationHandel(Animation_AnimationIng); } protected void Animation_AnimationIng(object sender, AnimationEventArgs e) { ButtonExt control = (ButtonExt)sender; control.Width = (int)((double)control.original_w + e.Transform * e.progressTime); control.Height = (int)((double)control.original_h + e.Transform * e.progressTime); int x = (int)((this.original_w - control.Width) / 2.0); int y = (int)((this.original_h - control.Height) / 2.0); control.Location = new Point((int)this.original_x + x, (int)this.original_y + y); } protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); this.loadOriginal(this.original_isload); this._Animation.AT = AnimationType.ElasticOut; this._Animation.Start(true, this._Animation.UsedTime); } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); this._Animation.AT = AnimationType.BackIn; this._Animation.Start(false, this._Animation.UsedTime); } private bool original_isload = false; private double original_w = 0.0;// 动画对象开始制定属性原始值 private double original_h = 0.0;// 动画对象开始制定属性原始值 private int original_x = 0;// 动画对象开始制定属性原始值 private int original_y = 0;// 动画对象开始制定属性原始值 private void loadOriginal(bool _isload) { if (!_isload) { this.original_w = this.Width; this.original_h = this.Height; this.original_x = this.Location.X; this.original_y = this.Location.Y; this.original_isload = true; } } /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); if (this._Animation != null) { this._Animation.Dispose(); } } base.Dispose(disposing); } }
源码下载:按钮动画控件.zip
标签:strong div ima str public rms wing return width
原文地址:https://www.cnblogs.com/tlmbem/p/11204624.html