按钮动画控件

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

 

转载于:https://www.cnblogs.com/tlmbem/p/11204624.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值